-1

I need to parse JSON. Unfortunately, I couldn't get name and rate from the JSON string as usual method described in here. Also, this one doesn't help me.

{"usd":
    {"code":"USD",
     "alphaCode":"USD",
     "numericCode":"840",
     "name":"U.S. Dollar",
     "rate":1.0857128644692,
     "date":"Mon, 21 Dec 2015 12:00:01 GMT"},
 "gbp":
    {"code":"GBP",
     "alphaCode":"GBP",
     "numericCode":"826",
     "name":"U.K. Pound Sterling",
     "rate":0.72830809326194,
     "date":"Mon, 21 Dec 2015 12:00:01 GMT"},
  "cad":
     {"code":"CAD",
      "alphaCode":"CAD",
      "numericCode":"124",
      "name":"Canadian Dollar",
      "rate":1.5123600265482,
      "date":"Mon, 21 Dec 2015 12:00:01 GMT"}
}

Result:

"U.S. Dollar" "1.0857128644692"

"Canadian Dollar" "1.5123600265482"

1
  • Please See my Answer on this Link. I hope you are clear with my Step. Commented Dec 21, 2015 at 14:34

1 Answer 1

4

try this solution

 try {

        JSONObject MainJsonObject = new JSONObject("Your Sting input data");

        Iterator keyNames = MainJsonObject.keys();

        while (keyNames.hasNext()) {

            String keyname = (String) keyNames.next();

            JSONObject jsonObject = MainJsonObject.getJSONObject(keyname);

            // parse this this jsonObjectas you required

        }
    }catch (Exception e) {
        e.printStackTrace();
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.