1

I want to parse this JSON String :

{
  lhs: "1 British pound",
  rhs: "1.6152 U.S. dollars",
  error: "",
  icc: true
}

but JSONArray returns null value.

3

1 Answer 1

3

current json string contain an jsonObject instead of JsonArray so parse it as :

// Convert String to Json Object
JSONObject jsonObject = new JSONObject("Pass_Your_Json_String");

// get lhs 
String str_lhs=jsonObject.getString("lhs");

// get rhs
String str_rhs=jsonObject.getString("rhs");

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

4 Comments

+1 for pointing that there is no JSONArray present. To add JSONArray will be in [] and JSONObject will be in {}.
@samadhanmedge : In current code link you are retuning null from doInBackground change it to return an ArrayList list of parsed values to onPostExecute and remove runOnUiThread beuase we can access UI from onPostExecute without using runOnUiThread
@ρяσѕρєя K: Ok, I got it, next time I'll remember this thing.
@samadhanmedge, remember to accept this answer. It makes SO work.

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.