“Android Studio JSON Parser” Réponses codées

Android Studio JSON Parser

/*
if respond is object
respond = { "a": "a", "b" : [1,2] }
*/
JSONObject jo = new JSONObject(respond); 

String a = jo.getString("a"); // a
JSONArray ja2 = jo.getJSONArray("b"); // [1,2]
int one = ja2.getInt(0) // 1
Ganz404

JSON Decode Android

public class test
{
    public static void main(String str[])
    {
        String jsonString = "{\"stat\": { \"sdr\": \"aa:bb:cc:dd:ee:ff\", \"rcv\": \"aa:bb:cc:dd:ee:ff\", \"time\": \"UTC in millis\", \"type\": 1, \"subt\": 1, \"argv\": [{\"type\": 1, \"val\":\"stackoverflow\"}]}}";
        JSONObject jsonObject = new JSONObject(jsonString);
        JSONObject newJSON = jsonObject.getJSONObject("stat");
        System.out.println(newJSON.toString());
        jsonObject = new JSONObject(newJSON.toString());
        System.out.println(jsonObject.getString("rcv"));
       System.out.println(jsonObject.getJSONArray("argv"));
    }
}
Condemned Chimpanzee

Android Studio JSON Parser

/*
if respond is array
respond = [ {"a": "a", "b" : [1,2] } ]
*/
JSONArray ja1 = new JSONArray(respond);
JSONObject jo= ja1.getJSONObject(0); // {"a": "a", "b" : [1,2] }

String a = jo.getString("a"); // a
JSONArray ja2 = jo.getJSONArray("b"); // [1,2]
Ganz404

Réponses similaires à “Android Studio JSON Parser”

Questions similaires à “Android Studio JSON Parser”

Plus de réponses similaires à “Android Studio JSON Parser” dans Java

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code