我想从json创建菜单和内容,你能给我一个解析这个json字符串的提示吗?
这是我的json:
{
"menu": {
"id": "file",
"value": "File",
"menuitem": {
"gadget": [
{
"judul_video": "Godigi TV",
"url_video": "url for video",
"url_poster": "url for poster",
"artikel_video": "Kakashi Article"
},
{
"judul_video": "TVRI Nasional",
"url_video": "url for video",
"url_poster": "url for poster",
"artikel_video": ""
},
{
"judul_video": "ANTV ",
"url_video": "url for video",
"url_poster": "url for poster",
"artikel_video": ""
}
],
"animasi": [
{
"judul_video": "Godigi TV",
"url_video": "url for video",
"url_poster": "url for poster",
"artikel_video": "Kakashi Article"
},
{
"judul_video": "TVRI Nasional",
"url_video": "url for video",
"url_poster": "url for poster",
"artikel_video": ""
},
{
"judul_video": "ANTV ",
"url_video": "url for video",
"url_poster": "url for poster",
"artikel_video": ""
}
],
"techno": [
{
"judul_video": "Godigi TV",
"url_video": "url for video",
"url_poster": "url for poster",
"artikel_video": "Kakashi Article"
},
{
"judul_video": "TVRI Nasional",
"url_video": "url for video",
"url_poster": "url for poster",
"artikel_video": ""
},
{
"judul_video": "ANTV ",
"url_video": "url for video",
"url_poster": "url for poster",
"artikel_video": ""
}
],
"cgt": [
{
"judul_video": "Godigi TV",
"url_video": "url for video",
"url_poster": "url for poster",
"artikel_video": "Kakashi Article"
},
{
"judul_video": "TVRI Nasional",
"url_video": "url for video",
"url_poster": "url for poster",
"artikel_video": ""
},
{
"judul_video": "ANTV ",
"url_video": "url for video",
"url_poster": "url for poster",
"artikel_video": ""
}
],
"info": [
{
"judul_video": "Godigi TV",
"url_video": "url for video",
"url_poster": "url for poster",
"artikel_video": "Kakashi Article"
},
{
"judul_video": "TVRI Nasional",
"url_video": "url for video",
"url_poster": "url for poster",
"artikel_video": ""
},
{
"judul_video": "ANTV ",
"url_video": "url for video",
"url_poster": "url for poster",
"artikel_video": ""
}
],
"news": [
{
"judul_video": "Godigi TV",
"url_video": "url for video",
"url_poster": "url for poster",
"artikel_video": "Kakashi Article"
},
{
"judul_video": "TVRI Nasional",
"url_video": "url for video",
"url_poster": "url for poster",
"artikel_video": ""
},
{
"judul_video": "ANTV ",
"url_video": "url for video",
"url_poster": "url for poster",
"artikel_video": ""
}
]
}
}
}
输出的是: animasi,gadget,techno等用于列表视图中的菜单,其中的数组是内容。
请帮助,我尝试搜索但不知道这个。 提前谢谢。
答案 0 :(得分:0)
要解析试试这个
JSONOBject jb = new JSONObject("jsonstring");
JSONOBject jb1 = jb.getJSONObject("menu");
String id = jb1.getString("id");
String value = jb1.getString("value");
JSONObject jb2 = jb1.getJSOnObject("menuitem");
JSONArray jr = (JSONArray)kb2.getJSONArray("gadget");
for(int i=0 ;i<jr.length();i++)
{
JSONOBject jb3 = (JSONObject) jr.get(i);
String judulvideo = jb3.getString("judul_video");
String url_poster = jb3.getString("url_poster");
String artikel_videor = jb3.getString("artikel_video");
}
同样解析JSONArray“techno”:[和其他人
{
表示JSONObject节点
[
表示JSONArray节点
您也可以使用Gson http://code.google.com/p/google-gson/