0

Here is part of the json file I am using (from YQL).

{
"query":{
  "count":1,
  "created":"2014-08-03T11:11:01Z",
  "lang":"en-US",
  "results":{
     "quote":{
        "symbol":"GOOGL",
        "Ask":"575.00",
      }
   }
 }
}

Here is the code I tried to use to parse:

           // get json string from url
            JSONObject json = jParser.getJSONFromUrl(JsonStringUrl);

            // get the array of users
            JSONObject query = json.getJSONObject("query");
            JSONObject results = query.getJSONObject("results");
            JSONObject quote  = results.getJSONObject("quote");

            String ask = quote.getString("ask");
            Log.e(TAG, "Ask: " + ask);

This doesn't work (as I assumed it wouldn't) but I am not really sure how I would go about changing it. Thanks for taking the time to read/answer this :)

1 Answer 1

3

That code looks fine to me other than that you've requested the value for the key "ask", and the key in the JSON is "Ask" (capital A). (Capitalization matters in JSON.)

Sign up to request clarification or add additional context in comments.

2 Comments

Ok now I feel silly, it works now :D thanks a bunch!
@BenSmith: :-) We've all done it. The question has to be: Why would they use all lower case for everything else, but a capital for that one key?

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.