简体   繁体   中英

How to read Json Android

i so confused ! i'm so trying to read this json but i can't :-( here is my code :

{"status":"loged_in","token":"8e88776a14f4da4ef8e00955f83e1397","nikeName":"سعید"}

        try {
            postTextandGetRespons("http://gfac.ir/KatibehPayam/Service/login.php");

            JSONArray messages = new JSONArray(responseString);

            for ( int i=0; i<= messages.length();i++){

                JSONObject c = messages.getJSONObject(i);

                Status[0] = c.getString("status");
                Status[1] = c.getString("token");
                Status[2] = c.getString("nikeName");

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

Your responseString contains an object not an array so use JSONObject instead of JSONArray

JSONObject message = new JSONObject(responseString);
String status = message.getString("status");
String token = message.getString("token");
String nikeName = message.getString("nikeName");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM