0

我在 JSON 中得到响应我想解析这个

    [
    {
        "fbuid": "100000462110782"
    },
    {
        "fullname": "Arun Pathania"
    },
    {
        "fbuid": "100000257902867"
    },
    {
        "fullname": "Shiju vargheae"
    },
    {
        "fbuid": "100003337246078"
    },
    {
        "fullname": "Smart Buzz"
    }
]

我尝试了以下方法:

JSONArray jArray = new JSONArray(result); 
for (int i=0; i < jArray.length(); i++) { 
    JSONObject oneObject = jArray.getJSONObject(i); // Pulling items from the array 
    u_id_json = oneObject.getString("fbuid");
    u_name_json = oneObject.getString("fullname");
}

错误

 error is coming is :--org.json.JSONException: No value for fullname –

请告诉我如何在android中解析这个

4

1 回答 1

2
JSONArray main;
    int i;
    JSONObject mainobj,fb,fname;
    String[] fbuid,fullname;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
            try {
                main = new JSONArray(jsonstring);
                Log.e(main.toString(),"string");
                fbuid=new String[main.length()];
                fullname=new String[main.length()];
                for( i=0;i<main.length();i++)
                {
                    mainobj = main.getJSONObject(i);
                    if(mainobj.has("fbuid"))
                    {
                        fbuid[i]=mainobj.getString("fbuid");
                        Log.e(fbuid[i],"string");
                    }
                    else if(mainobj.has("fullname"))
                    {
                        fullname[i]=mainobj.getString("fullname");
                        Log.e(fullname[i],"string");
                    }
                }

            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();

试试这个

于 2013-05-07T07:37:57.270 回答