Android 从json数组中获取元素
如何在Android上获取此数组的值?请尝试以下代码:Android 从json数组中获取元素,android,json,Android,Json,如何在Android上获取此数组的值?请尝试以下代码: [{"id":"1","capacity":"150","type":"conference","prix":"0","description":"description","image":""},{"id":"2","capacity":"200","type":"Formation","prix":"0","description":"desc"}] 试试看{ String yourstring=“在此处添加JSON数组”; JSON
[{"id":"1","capacity":"150","type":"conference","prix":"0","description":"description","image":""},{"id":"2","capacity":"200","type":"Formation","prix":"0","description":"desc"}]
试试看{
String yourstring=“在此处添加JSON数组”;
JSONArray temp=新的JSONArray(您的字符串);
对于(int i=0;i
试试我的代码,希望有帮助。
try{
String yourstring = "ADD YOUR JSON ARRAY HERE";
JSONArray temp = new JSONArray(yourstring);
for (int i = 0; i < temp.length(); i++) {
JSONObject row = (JSONObject) temp.get(i);
String id = row.getString("id");
String capacity= row.getString("capacity");
String type= row.getString("type");
String prix= row.getString("prix");
String description = row.getString("description");
// do something with each variable
}
}catch(Exception e){
e.printstacktrace()
}