spark85 / json-path

Automatically exported from code.google.com/p/json-path
0 stars 0 forks source link

slash to backslash #69

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
jsonpath 1.2.0

in json source we have a array of http addresses.

and when I do in follow
List<String> nameSpaces = JsonPath.read(text, "$..serviceNamespace");

I get 
["http:\/\/soa.ctrip.com\/framework\/data_arch\/v1","http:\/\/...

but inspected should be ["http:\\soa.ctrip.com\framework\data_arch\v1"...

Original issue reported on code.google.com by remoteja...@gmail.com on 15 Feb 2015 at 7:23

GoogleCodeExporter commented 9 years ago
Just tried this:

import static com.jayway.jsonpath.JsonPath.read;
import static org.assertj.core.api.Assertions.assertThat;

public class UrlTest {
    @Test
    public void test(){
        String json = "[\"http://www.jayway.com/sharing-knowledge/blog/\"]";

        assertThat(read(json, "$[0]")).isEqualTo("http://www.jayway.com/sharing-knowledge/blog/");
    }
}

and it works just fine. Have you confused '/' and '\' ? 

Please provide a simple example.

Original comment by kalle.st...@gmail.com on 20 Feb 2015 at 1:17

GoogleCodeExporter commented 9 years ago
OK think I know what you are doing. The deafault JsonProvider uses standard 
Java Lists and Maps. So if yo do a to string it will not work. Check this out:

import com.jayway.jsonpath.Configuration;
import org.junit.Test;
import java.util.List;
import static com.jayway.jsonpath.JsonPath.read;
import static org.assertj.core.api.Assertions.assertThat;

public class UrlTest {
    @Test
    public void test(){
        String json = "[\"http://www.jayway.com/sharing-knowledge/blog/\"]";
        List<String> res = read(json, "$[*]");
        assertThat(res).containsExactly("http://www.jayway.com/sharing-knowledge/blog/");

        String toJsonString = Configuration.defaultConfiguration().jsonProvider().toJson(res);
        String listToString = res.toString();

        System.out.println(toJsonString); //prints : ["http://www.jayway.com/sharing-knowledge/blog/"]
        System.out.println(listToString); //prints:  ["http:\/\/www.jayway.com\/sharing-knowledge\/blog\/"]
    }
}

Original comment by kalle.st...@gmail.com on 20 Feb 2015 at 1:30

GoogleCodeExporter commented 9 years ago
I'm very sorry for my late reply due to the Spring Festival.

Yes,I use toString method directly.so .. Thanks for your help.

JsonPath did relieve me of the life!

Original comment by remoteja...@gmail.com on 1 Mar 2015 at 4:06