2
我正在使用杰克逊解析api结果,这似乎运作良好。杰克逊解析特定数组
的Java:
public static void jsonIn(String st){
try {
JsonFactory jfactory = new JsonFactory();
/*** read from URL ***/
JsonParser jParser = jfactory.createJsonParser(new URL(st));
// loop until token equal to "}"
while (jParser.nextToken() != JsonToken.END_ARRAY) {
String fieldname = jParser.getCurrentName();
if ("id".equals(fieldname)) {
// current token is "id",
// move to next, which is "id"'s value
try{
jParser.nextToken();
}
catch (Exception e){
}
System.out.println(jParser.getText()); // display id
}
}
jParser.close();
} catch (JsonGenerationException e) {
e.printStackTrace();
}
}
问:
However-我想要的结果(现场: “ID”)都在阵 “项目”。上面的代码从第一个数组“查询”开始,只发送给我一个名为“id”的元素,我不关心它。然后它停止基于while语句的解析并且不会到达“items”数组。我如何更改我的代码以跳到我感兴趣的数组“项目”,以便我可以获得我想要的“id”字段?
JSON:
{
"app": "Sale",
"avail": {
"type": "application/json",
},
"queries": {
"unAvailURIs": [
{
"id": "1sdf6gf3jf80dhb3",
"results": "57",
"searchTerms": "lycos.com",
"startIndex": 11
}
],
"apiSource": [
{
"title": "go****y",
"totalResults": "579000",
"auctionPhrase": "lycos.com",
"count": 10,
"startIndex": 1,
"id": "in",
}
]
},
"pullAPI": {
"search": "lycos.com"
},
"searchInformation": {
"searchTime": 0.025345,
"totalResults": "57600100",
},
"items": [
{
"id": "GD172993",
"title": "lycos.com",
....