Open GoogleCodeExporter opened 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
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
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
Original issue reported on code.google.com by
remoteja...@gmail.com
on 15 Feb 2015 at 7:23