{ "success": true, "message": null, "code": null, "elapsed": 0.1291, "data": { "CSPA:BTC": { "cspa": 8012.00601685, "cspa_change_24h": -467.52638691, "cspa_change_24h_pct": -5.51, "volume_btc_24h": 634847.37, "volume_usd_24h": 5086400987.27, "updated": 1522132576 } } }
This is the JSON data that comes out when you run the API code.
I want to do JSON parsing
I don't know where to write the code for JSON parsing.
Do you have to do it with a different class in the same package?
Or I wonder if I have to take the class off the main and fill it out.
Also, in order to extract cspa in the data,
JSONArray bodyArray = (JSONArray) object.get("CSPA:BTC");
for(int i = 0 ; i < bodyArray.size(); i++)
{
JSONObject data = (JSONObject) bodyArray.get(i);
System.out.println(data.get("cspa").toString());
System.out.println(data.get("cspa_change_24h").toString());
System.out.println(data.get("cspa_change_24h_pct").toString());
}
Is this the right code?
Learn only what is necessary without learning JAVA.
only what you need through the rule of thumbAs we worked on it
I need your help.
java json api parsing
If you search with the json beautiful
keyword, there are many sites that change the structure of the json data to make it easier to see.
{
"success":true,
"message":null,
"code":null,
"elapsed":0.1291,
"data":{
"CSPA:BTC":{
"cspa":8012.00601685,
"cspa_change_24h":-467.52638691,
"cspa_change_24h_pct":-5.51,
"volume_btc_24h":634847.37,
"volume_usd_24h":5086400987.27,
"updated":1522132576
}
}
}
JSONarray
should be used to parse the array []. All of the above data are in brackets {} It's an object using . You can approach it sequentially as below. This code doesn't matter where you are.
JSONObject dataObject = (JSONObject) parsedObject.get("data");
JSONObject targetObject = (JSONObject) dataObject.get("CSPA:BTC");
targetObject.get("cspa");
targetObject.get("cspa_change_24h");
...
© 2024 OneMinuteCode. All rights reserved.