JsonFactory f = new MappingJsonFactory();
JsonParser jp = f.createParser(res);
JsonToken current;
current = jp.nextToken();
if (current != JsonToken.START_OBJECT) {
System.out.println("Error: root should be object: quiting.");
return;
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
String fieldName = jp.getCurrentName();
// move from field name to field value
current = jp.nextToken();
if (fieldName.equals("row")) {
if (current == JsonToken.START_ARRAY) {
while (jp.nextToken() != JsonToken.END_ARRAY) {
JsonNode node = jp.readValueAsTree();
Log.e("KFF", node.get("col0").asText());
}
} else {
Log.e("KFF", "Error: records should be an array: skipping.");
jp.skipChildren();
}
} else {
Log.e("KFF", "Unprocessed property: " + fieldName);
jp.skipChildren();
}
}
} catch (JsonParseException e) {
e.printStackTrace();
} catch (JsonProcessingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20csv%20where%20url%3D%22http%3A%2F%2Fichart.finance.yahoo.com%2Ftable.csv%3Fs%3DYHOO%26a%3D11%26b%3D10%26c%3D2011%26d%3D10%26e%3D10%26f%3D2013%26g%3Dd%22%3B&format=json&diagnostics=true&callback=
我目前正在使用上面的方法来解析来自网络的 JSON 响应(使用 JACKSON JSON PARSING LIBARY),但是我不知道如何解析嵌套的 json 数组,例如以下,即如何深入每个json 数组直到“行”,然后能够读取每个“colx”消除“未处理的属性”
对不起,英语的可怕质量,已经很晚了,我在描述它方面不知所措。