【发布时间】:2014-10-02 02:35:27
【问题描述】:
我有一个字符串如下,我想把它转换成一个 JSON 对象,然后提取“文本”字段的所有值:
{
"id": "/m/030qb3t",
"property": {
"/travel/travel_destination/tourist_attractions": {
"valuetype": "object",
"values": [
{
"text": "Hollywood Wax Museum",
"lang": "en",
"id": "/m/07_dsf",
"creator": "/user/rumifield",
"timestamp": "2008-12-27T17:02:32.000Z"
},
{
"text": "Hollywood Walk of Fame",
"lang": "en",
"id": "/m/0qjfl",
"creator": "/user/rumifield",
"timestamp": "2008-12-27T17:02:32.000Z"
},
{
"text": "TCL Chinese Theatre",
"lang": "en",
"id": "/m/04n2h_",
"creator": "/user/rumifield",
"timestamp": "2008-12-27T17:02:32.000Z"
},
{
"text": "Museum of Tolerance",
"lang": "en",
"id": "/m/04by8k",
"creator": "/user/rumifield",
"timestamp": "2008-12-27T17:02:32.001Z"
},
{
"text": "Getty Center",
"lang": "en",
"id": "/m/01mvl6",
"creator": "/user/rumifield",
"timestamp": "2008-12-27T17:02:32.001Z"
},
{
"text": "Museum of Contemporary Art, Los Angeles",
"lang": "en",
"id": "/m/02816j",
"creator": "/user/rumifield",
"timestamp": "2008-12-27T17:02:32.001Z"
},
{
"text": "Griffith Park",
"lang": "en",
"id": "/m/02sdph",
"creator": "/user/rumifield",
"timestamp": "2008-12-27T17:02:32.001Z"
},
{
"text": "Hollywood Boulevard",
"lang": "en",
"id": "/m/035zpq",
"creator": "/user/rumifield",
"timestamp": "2008-12-27T17:02:32.002Z"
},
{
"text": "Olvera Street",
"lang": "en",
"id": "/m/030svs",
"creator": "/user/rumifield",
"timestamp": "2008-12-27T17:02:32.002Z"
},
{
"text": "Centinela Adobe",
"lang": "en",
"id": "/m/04drm4",
"creator": "/user/supergmackenz",
"timestamp": "2011-12-13T18:45:26.003Z"
}
],
"count": 27.0
}
}
}
我试过了
JsonParser jsParser = new JsonParser();
JsonObject jsObject = (JsonObject)jsParser.parse(jsonStr);
String text=jsObject.getString("text");
但它不起作用,我不知道如何提取所有“文本”值,任何帮助将不胜感激,谢谢!
【问题讨论】: