我有一个Json数组作为字符串,没有名称,我想解析它 我怎么能在android中做到这一点?
我的JsonArray是:
[
{
"categoryId":1,
"Title":"Rock",
"songs":null
},
{
"categoryId":2,
"Title":"Jaz",
"songs":null
}
]
答案 0 :(得分:11)
试试这个..
JSONArray jsonarray = new JSONArray(json);
for (int i = 0; i < jsonarray.length(); i++) {
JSONObject jsonobj = jsonarray.getJSONObject(i);
System.out.println("categoryId : " + i + " = " + jsonobj.getString("categoryId"));
System.out.println("Title : " + i + " = " + jsonobj.getString("Title"));
System.out.println("songs : " + i + " = " + jsonobj.getString("songs"));
}
答案 1 :(得分:2)
试试这个,
JSONArray array1=new JSONArray(json);
for(int i=0;i<array1.length;i++)
{
JSONObject obj1 = array1.getJSONObject(i);
String categoryId = obj1.getString("categoryId");
String Title = obj1.getString("Title");
String songs = obj1.getString("songs");
}
答案 2 :(得分:1)
您可以使用:
JSONArray a = new JSONArray(myJsonString);
答案 3 :(得分:1)
试试这个:
JSONArray arr = new JSONArray(jsonString);
for (int i = 0; i < arr.length(); i++) {
JSONObject obj = arr.getJSONObject(i);
String title = obj.getString("Title");
}
答案 4 :(得分:0)
这样做
JSONArray jArr = new JSONArray(jsonString);
for (int i = 0; i < jArr.length(); i++) {
Syste.out.println("Object : " + i + " = " + jArr.getJSONObject(i));
}