JSONArray 解析多维数组
JSONArray parsing a multidimensional array
我有一个格式为 jArray 的数组:
{"users":[
{
"user_id":6,
"user_name":"Ted Vanderploeg",
"email":"test5@test.com",
"additional_info":[["HP","Chief Sales Officer","","",1]]
},
{
"user_id":59,
"user_name":"Lindsay White",
"email":"test12260@test.com",
"additional_info":[["Microsoft","Global Head","","",1]]
}
]
}
现在我需要从 additional_info 数组中获取值 "Microsoft"。这就是我正在尝试的:
for(int i=0;i<jArray.length();i++) {
JSONObject jsonObject = new JSONObject(jArray.getString(i));
String workInfo = jsonObject.getString("additional_info");
Log.i("MyActivity", "got work obj as " + workInfo.toString());
}
现在我得到 workInfo 作为 [["Microsoft","Global Head","","",1]]。坚持下一步如何进行,以获得微软的价值。
它看起来像是 JSONArray 中的 JSONArray
for(int i=0;i<jArray.length();i++) {
JSONObject jsonObject = new JSONObject(jArray.getString(i));
JSONArray workinfo = jsonObject.optJSONArray("additional_info");
if (workinfo != null) {
for(int j=0;j<workinfo.length();j++) {
JSONArray values = workinfo.optJSONArray(j);
for(int z=0;z<values.length();z++) {
Log.i("MyActivity", "got work obj as " + values.optString(z));
}
}
}
}
我有一个格式为 jArray 的数组:
{"users":[
{
"user_id":6,
"user_name":"Ted Vanderploeg",
"email":"test5@test.com",
"additional_info":[["HP","Chief Sales Officer","","",1]]
},
{
"user_id":59,
"user_name":"Lindsay White",
"email":"test12260@test.com",
"additional_info":[["Microsoft","Global Head","","",1]]
}
]
}
现在我需要从 additional_info 数组中获取值 "Microsoft"。这就是我正在尝试的:
for(int i=0;i<jArray.length();i++) {
JSONObject jsonObject = new JSONObject(jArray.getString(i));
String workInfo = jsonObject.getString("additional_info");
Log.i("MyActivity", "got work obj as " + workInfo.toString());
}
现在我得到 workInfo 作为 [["Microsoft","Global Head","","",1]]。坚持下一步如何进行,以获得微软的价值。
它看起来像是 JSONArray 中的 JSONArray
for(int i=0;i<jArray.length();i++) {
JSONObject jsonObject = new JSONObject(jArray.getString(i));
JSONArray workinfo = jsonObject.optJSONArray("additional_info");
if (workinfo != null) {
for(int j=0;j<workinfo.length();j++) {
JSONArray values = workinfo.optJSONArray(j);
for(int z=0;z<values.length();z++) {
Log.i("MyActivity", "got work obj as " + values.optString(z));
}
}
}
}