I have this following JSON string and i want extract the json array into separate string using android but i facing JSON exception.
try
{
String str="[{'Festivals':{'Fesa1':'english is good ','Fesb1':'my english is not so accurate','Fesa2':'oriya is very nice language','Fesb2':'my oriya is absolutely good','Fesa3':'cricket is a very popular game ','Fesb3':'cricket is life for indian','Fesa4':'hockey is the original game for india','Fesb4':'hockey needs to improve ','Fesa5':'computer is a very functional device','Fesb5':'computer is very helpful to mankind'}}] ";
JSONArray jsonArray = new JSONArray(str);
String abc1=null;
String abc2=null;
String abc3=null;
int i2=0;
for(int i=0;i<jsonArray.length();i++)
{
JSONObject e = jsonArray.getJSONObject(i);
JSONObject jsonObject = e.getJSONObject("Festivals");
tt.setText(tt.getText().toString()+String.valueOf("Total Array Length: "+jsonArray.length()+"\n"));
for(int i1=0;i1<jsonObject.length();i1++)
{
i2=i1+1;
abc1=jsonObject.getString("Fesa"+i2);
abc2=jsonObject.getString("Fesb"+i2);
tt.setText(tt.getText().toString()+String.valueOf(abc1+" - "+abc2+" - "+" \n"));
}
}
}
catch (JSONException e)
{
tt.setText("JSON Exception");
}
So , i am getting JSONExcepiton error. Please help me out. Please suggest me some solution
Thanks in Advance !!!
Make sure JSON is valid as the answer above. In case of any special characters you will need to escape them, i.e.
Your json is not valid. Check it @ http://jsonlint.com/
It should be
Parsing
Edit:
Change your json to below and use the below you will get all values
Parsing