Android Regd:从json url获取值

Android Regd:从json url获取值,android,Android,我想在中获取id^&内容值 我试过的是 try { JSONObject jsonObj = new JSONObject(parsingUrl); // If you have array JSONArray resultArray = jsonObj.getJSONArray("id"); // Here you will get the Array // Iterate the loop for (int

我想在中获取id^&内容值

我试过的是

try {
        JSONObject jsonObj = new JSONObject(parsingUrl);

        // If you have array
        JSONArray resultArray = jsonObj.getJSONArray("id"); // Here you will get the Array

        // Iterate the loop
        for (int i = 0; i < resultArray.length(); i++) {
            // get value with the NODE key
            JSONObject obj = resultArray.getJSONObject(i);
            String name =  obj.getString("content");
        }

        // If you have object
        //String result1 = jsonObj.getString("result");

    } catch (Exception e) {
        e.printStackTrace();
    }
试试看{
JSONObject jsonObj=新的JSONObject(parsingUrl);
//如果你有一个数组
JSONArray resultArray=jsonObj.getJSONArray(“id”);//这里您将获得数组
//迭代循环
对于(int i=0;i

谢谢你提到的url没有json数组,解析如下

try {
        JSONObject jsonObj = new JSONObject(resultfromUrl);

        int id = jsonObj.getInt("id"); 
        String name =  jsonObj.getString("content");
    } catch (JSONException e) {
        e.printStackTrace();
    }

你能测试上面提到的代码吗?我试过oncreate。它没有设置值。现在我不是在发出请求。我正在oncreate中添加以下代码。如果没有Asynchtasknowed JSONObject(resultfromUrl),这是不可能的。。。您必须执行AsyncTask才能从url获取结果。直接在JSONObject中传递url是行不通的。如果没有AsyncTaskplz,这是不可能的。请将java文件发送给我