I have a JSON like,
{
"Area1": "areacode1",
"Area2": "areacode2",
"Area3" : "areacode3"
}
I want to parse the json and iterate "area" it to autocompletetextview, My code is,
//Reading JSON from local file
public String loadJSONFromAsset() {
String json = null;
try {
InputStream is = getAssets().open("arealist.json");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
return json;
}
//parsing and iterating the json...
try {
JSONObject obj = new JSONObject(loadJSONFromAsset());
Iterator<String> keys= obj.keys();
while (keys.hasNext())
{
String keyValue = (String)keys.next();
String valueString = obj.getString(keyValue);
Log.d("Details-->",valueString);
}
} catch (JSONException e) {
e.printStackTrace();
}
I am getting the error as "Type mismatch:can't convert JSONObject to JSONArray",I want to know how to convert JSONObject to string and iterate to List.I am new to android so confused how to proceed further Kindly help,Thanks in advance.