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