Abdul.Moqueet Abdul.Moqueet - 1 year ago 55
Android Question

how to parse this JSONArray

Hi guys i have this

I'm having hard time to parse it.

Here's the

"query": {
"count": 2,
"created": "2016-11-07T15:29:47Z",
"lang": "en-US",
"results": {
"rate": [{
"id": "USDINR",
"Name": "USD/INR",
"Rate": "66.7700",
"Date": "11/7/2016",
"Time": "3:27pm",
"Ask": "66.8000",
"Bid": "66.7700"
}, {
"id": "USDEUR",
"Name": "USD/EUR",
"Rate": "0.9060",
"Date": "11/7/2016",
"Time": "3:29pm",
"Ask": "0.9065",
"Bid": "0.9060"

As you can see above there are two "Rate" I want to store first "Rate" to a String array called
and second "Rate" to

Here what I'm trying.

JSONObject object = new JSONObject(JSON);

JSONObject rateObject = object.getJSONObject("rate");
JSONArray rateArray = rateObject.getJSONArray("Rate");
result[0] = rateArray.getString(0);
result[1] = rateArray.getString(1);

I know maybe I'm doing this like stupid. So please help me out.

Answer Source

Try this:

JSONArray rateArray = new JSONObject(JSON)
result[0] = rateArray.getJSONObject(0).getString("Rate");
result[1] = rateArray.getJSONObject(1).getString("Rate");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download