codecrazer codecrazer - 1 month ago 10
JSON Question

org.json.JSONException: Value <feed of type java.lang.String cannot be converted to JSONArray

In android studio,my code keep throwing exception and shows:
org.json.JSONException: Value

my Json is like this

[
{"Id":"CF","Name":"leo","County":"miami"},
{"Id":"CFS","Name":"lo","County":"ami"},
{"Id":"CFd","Name":"lei","County":"mimi"}
]


the Json is very long, I just post some of it;
then some part of my java code which keep throw exception is this:

try {
JSONArray rainArray=new JSONArray(rainJSON);
int len=rainArray.length();
for (int i = 0; i < len; i++) {
JSONObject current = rainArray.getJSONObject(i);
}
catch(JSONException e) {
Log.e("query", "wrong in parsing the rainJSON results", e);
}


Thank you for your help!!

Answer Source

I finally solve my problem, I found it is because I add / to my URL, so it link to RSS, not the JSon, I just delete the / , and my app works. If someone encouter with this problem, there are three things you have to check:

  1. check if your link links to Json page
  2. check the Json page contain correct Json, correct means syntax correct
  3. realize the difference between Json object and Json array