Answers for "android studio json parser"

0

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"));
    }
}
Posted by: Guest on July-23-2020
0

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
Posted by: Guest on July-05-2021
0

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]
Posted by: Guest on July-05-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language