0

My code:

string result = "[{"lat":"b", "lon":"d", "ulica":"ulica1"}]";
jArray = new JSONArray(result);
tab =new String[jArray.length()];
json = jArray.getJSONObject(0);

tab[0]=json.getString("lat");
tab[1]=json.getString("lon");  
tab[2]=json.getString("ulica");

it throws jsonException, no value for lon. Can anyone help me?

It was my mistake instead of lon I had lot in my result string... I was looking for this misspelling from early morning .... ;P

2
  • 1
    Can you post the message in the exception please? Commented Jan 3, 2012 at 9:03
  • What exact error message you are getting? Commented Jan 3, 2012 at 9:05

3 Answers 3

3

you must escape " with \" so instead of "a" you need to have \"a\"

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

Comments

0

I think these lines are the problem:

tab[0]=json.getString("lat"); tab[1]=json.getString("lon");
tab[2]=json.getString("ulica");

'lat', 'lon' and 'ulica' aren't mentioned in the JSON, so they won't be found. Try this:

tab[0]=json.getString("a"); tab[1]=json.getString("c");

Then you may get 'b' and 'd' respectively.

Note this is untested.

Comments

0

jArray.length() is actualy 1, so there was another(outOfRangeException) mistake.

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.