JSONの要素にアクセスするには?

Ostap:
 @Override
    protected void onPostExecute(String response) {
        String firstName = null;
        String lastName = null;
        try {
            JSONObject jsonResponse = new JSONObject(response);
            JSONArray jsonArray = jsonResponse.getJSONArray("");
            JSONObject userInfo = jsonArray.getJSONObject(0);

            firstName = userInfo.getString("id");
            lastName = userInfo.getString("id");

        }
        catch (JSONException e){
            e.printStackTrace();
        }

私は、このJSONファイル持ってhttps://api.myjson.com/bins/1a5t7w私はthatsの値へのアクセスもが、私はこのコードを使用することができますが、それは仕事をdoesnの`tどのように?それはnullを返します@ @

gyosida:
// since you know is an array, create a JSONArray based on your response String    
JSONArray array = JSONArray(response)
// obtain the first element of your array as a JSONObject
JSONObject jsonObject = array.getJSONObject(0)
// once you get the jsonObject you can start getting the values you need
String id = jsonObject.getString("id")

それが役に立てば幸い!

おすすめ

転載: http://10.200.1.11:23101/article/api/json?id=378636&siteId=1