“Android Studio Json Parser” Kode Jawaban

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 mendekode 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

Jawaban yang mirip dengan “Android Studio Json Parser”

Pertanyaan yang mirip dengan “Android Studio Json Parser”

Lebih banyak jawaban terkait untuk “Android Studio Json Parser” di Java

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya