JsonPath仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.1 KiB

package com.jayway.jsonpath;
import org.junit.Test;
13 years ago
import java.util.List;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
13 years ago
import static junit.framework.Assert.assertTrue;
/**
* Created by IntelliJ IDEA.
* User: kallestenflo
* Date: 2/29/12
* Time: 8:42 AM
*/
public class IssuesTest {
@Test
public void issue_7() throws Exception {
String json = "{ \"foo\" : [\n" +
" { \"id\": 1 }, \n" +
" { \"id\": 2 }, \n" +
" { \"id\": 3 }\n" +
" ] }";
assertNull(JsonPath.read(json, "$.foo.id"));
}
@Test
public void issue_11() throws Exception {
13 years ago
String json = "{ \"foo\" : [] }";
List<String> result = JsonPath.read(json, "$.foo[?(@.rel= 'item')][0].uri");
System.out.println(JsonPath.compile("$.foo[?(@.rel= 'item')][0].uri").isPathDefinite());
System.out.println(JsonPath.compile("$.foo[?(@.rel= 'item')][0]").isPathDefinite());
System.out.println(JsonPath.compile("$.foo[?(@.rel= 'item')]").isPathDefinite());
assertTrue(result.isEmpty());
}
}