Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从android中没有数组名的json中获取数据?_Android_Json - Fatal编程技术网

如何从android中没有数组名的json中获取数据?

如何从android中没有数组名的json中获取数据?,android,json,Android,Json,我想从此链接获取url: "http://graph.facebook.com/10202459285618351/picture?type=large&redirect=false" 结果如下: { “数据”:{ “url”:“1/s200x200/10342822\U 10202261537234765\U 3194866551853134720\U n.jpg”, “is_剪影”:错误 } } 我试过了 private class GetContacts extends Asy

我想从此链接获取url:

 "http://graph.facebook.com/10202459285618351/picture?type=large&redirect=false"
结果如下:

{ “数据”:{ “url”:“1/s200x200/10342822\U 10202261537234765\U 3194866551853134720\U n.jpg”, “is_剪影”:错误 } }

我试过了

private class GetContacts extends AsyncTask<Void, Void, Void> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        // Showing progress dialog
        pDialog = new ProgressDialog(AccountActivity.this);
        pDialog.setMessage("Please wait...");
        pDialog.setCancelable(false);
        pDialog.show();

    }

    @Override
    protected Void doInBackground(Void... arg0) {
        // Creating service handler class instance
        ServiceHandler sh = new ServiceHandler();

        String jsonStr = sh.makeServiceCall(fbPicURL, ServiceHandler.GET);

        Log.d("Response: ", "> " + jsonStr);

        if (jsonStr != null) {
            try {
                JSONObject jsonObj = new JSONObject(jsonStr);

                // Getting JSON Array node
                fbRealURL = jsonObj.getString("url");


                    // Phone node is JSON Object
                    Toast.makeText(AccountActivity.this, fbRealURL,
                            Toast.LENGTH_LONG).show();
                    // tmp hashmap for single contact

                }
             catch (JSONException e) {
                e.printStackTrace();
            }
        } else {
            Log.e("ServiceHandler", "Couldn't get any data from the url");
        }

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        // Dismiss the progress dialog
        if (pDialog.isShowing())
            pDialog.dismiss();
        /**
         * Updating parsed JSON data into ListView
         * */
        Toast.makeText(AccountActivity.this, fbRealURL,
                Toast.LENGTH_LONG).show();
    }

}
私有类GetContacts扩展异步任务{
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
//显示进度对话框
pDialog=新建进度对话框(AccountActivity.this);
setMessage(“请稍候…”);
pDialog.setCancelable(假);
pDialog.show();
}
@凌驾
受保护的Void doInBackground(Void…arg0){
//创建服务处理程序类实例
ServiceHandler sh=新的ServiceHandler();
字符串jsonStr=sh.makeServiceCall(fbPicURL,ServiceHandler.GET);
Log.d(“响应:”、“>”+jsonStr);
if(jsonStr!=null){
试一试{
JSONObject jsonObj=新的JSONObject(jsonStr);
//获取JSON数组节点
fbRealURL=jsonObj.getString(“url”);
//电话节点是JSON对象
Toast.makeText(AccountActivity.this,fbRealURL,
Toast.LENGTH_LONG).show();
//单触点的tmp哈希映射
}
捕获(JSONException e){
e、 printStackTrace();
}
}否则{
Log.e(“ServiceHandler”,“无法从url获取任何数据”);
}
返回null;
}
@凌驾
受保护的void onPostExecute(void结果){
super.onPostExecute(结果);
//关闭进度对话框
if(pDialog.isShowing())
pDialog.disclose();
/**
*将解析的JSON数据更新到ListView中
* */
Toast.makeText(AccountActivity.this,fbRealURL,
Toast.LENGTH_LONG).show();
}
}

但是返回null并没有崩溃

必须先获取数据对象,如下所示:

     try {
            JSONObject jsonObj = new JSONObject(jsonStr);


            fbRealURLObj = jsonObj.getJSONObject("data");

            fbRealURL = fbRealURLObj.getString("url");

                // Phone node is JSON Object
                Toast.makeText(AccountActivity.this, fbRealURL,
                        Toast.LENGTH_LONG).show();
                // tmp hashmap for single contact

            }

仍然没有得到任何价值你在logcat中得到任何错误吗??在此处发布您的logcat错误。它给了我:来自nativeGetEnabledTags的意外值:0如果可以,您可以发布完整代码。。你的asynctask看起来很好。。我也会这么做的。。。你能发布完整的logcat输出吗