我在解析JSON時遇到了問題。我有一個字符串,例如,在android中解析JSON數據
String result = "[{"id":"1","brand_name":"Unilever","brand_image":"collaboration_2.jpg","brand_description":"Unilever is the world's leading company and blah blah ","is_active":"1"},{"id":"2","brand_name":"Engro","brand_image":"people-icon-in-vector-format14.jpg","brand_description":"Engro is another brand and blah blah blah blah\r\n","is_active":"1"}]";
這裏試圖碼我努力,但得到空指針異常
String brands[] = null;
JSONArray data = new JSONArray(result);
for(int j=0; j<data.length();j++){
brands[j] = data.getJSONObject(j).getString("brand_name");
}
你是正確的。我建議OP使用'ArrayList'和'add()'方法。 –