小编DPK*_*K27的帖子

org.json.JSONArray无法转换为JSONObject

我是新手JSON,我正在接受以下异常:

org.json.JSONArray cannot be converted to JSONObject 在try部分的第一行本身.

请帮我删除这个.这是我的代码:

try {   
    JSONObject json = new JSONObject(strResponse);

    //Get the element that holds the internship ( JSONArray )
    JSONArray name = json.names();
    JSONArray  internships = json.toJSONArray(name);

    //Loop the Array
    for(int i=0;i < internships.length();i++) {     
        Log.e("Message","loop");
        HashMap<String, String> map = new HashMap<String, String>();
        JSONObject e = internships.getJSONObject(i);
        map.put("id",  String.valueOf("id"));
        map.put("title", "Title :" + e.getString("title"));
        map.put("company", "Company : " +  e.getString("company"));
        map.put("category", "Category : " +  e.getString("category"));
        mylist.add(map);
    } 
} catch(JSONException e) …
Run Code Online (Sandbox Code Playgroud)

java android json

14
推荐指数
2
解决办法
4万
查看次数

标签 统计

android ×1

java ×1

json ×1