您好,有没有人帮我在textView上以正确的方式显示这种类型的JSON数组。任何回复都将受到高度赞赏!
{"result":[{"drugbrand":"Bactiflox","manu":"Mepha","details":"Tabs, 250 mg (10 s = Ke: 780.00), 500mg (10 s = Ke: 1,025.00), 750 mg (10 s = Ke: 1,345.00)"}]}
使用belo代码但它发出异常:org.json.JSONException:java.lang.String类型的值无法转换为JSONObject
try {
JSONArray jArray=new JSONArray(result);
for(int i=0;i<jArray.length();i++){
String name = jArray.getJSONObject(i).getString("drugbrand");
String manufacturer = jArray.getJSONObject(i).getString("manu");
String info = jArray.getJSONObject(i).getString("details");
jsonText = name + "\n" + manufacturer + "\n" + info;
outputText.setText(jsonText);
}
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
答案 0 :(得分:2)
您的回答它是JSONObject
:
{"result":[{"drugbrand":"Bactiflox","manu":"Mepha","details":"Tabs, 250 mg (10 s = Ke: 780.00), 500mg (10 s = Ke: 1,025.00), 750 mg (10 s = Ke: 1,345.00)"}]}
您只需创建此JSONObject
即可获得JSONArray
:
JSONObject jObj = new JSONObject(result);
JSONArray jArray= jObj.getJSONArray("result");
JSONArray
位于JSONObject
内,标记为&#34;结果&#34;