i have searched questions like that but couldnot get success.
I have JSON data lke that http://oep.esy.es/item_connect.php
{
"items":[
{
"id":"7",
"name":"bir",
"image":"6051-1.png",
"number":"1",
"shape":"\u015eekilsiz",
"color":"turuncu"
},
{
"id":"8",
"name":"d\u00f6rt",
"image":"1727-4.png",
"number":"1",
"shape":"\u015eekilsiz",
"color":"turuncu"
},
{
"id":"9",
"name":"iki",
"image":"2667-2.png",
"number":"1",
"shape":"\u015eekilsiz",
"color":"turuncu"
},
{
"id":"10",
"name":"\u00fc\u00e7",
"image":"9998-3.png",
"number":"1",
"shape":"\u015eekilsiz",
"color":"turuncu"
},
{
"id":"11",
"name":"be\u015f",
"image":"7005-5.png",
"number":"1",
"shape":"\u015eekilsiz",
"color":"turuncu"
},
{
"id":"12",
"name":"alt\u0131",
"image":"9377-6.png",
"number":"1",
"shape":"\u015eekilsiz",
"color":"turuncu"
},
{
"id":"13",
"name":"elma",
"image":"1656-1001.png",
"number":"1",
"shape":"\u015eekilsiz",
"color":"k\u0131rm\u0131z\u0131"
}
],
"success":1
}
At first there is word of items and at last there is word of success. There are out of array. WHen i delete them, i can success.
StringBuilder sb = new StringBuilder();
sb.append(json+"\n");//Log.d(TAG, "sb "+sb.toString());
}
try {Log.d(TAG, "xx ");
JSONArray mJsonArray = new JSONArray(sb);Log.d(TAG, "xx x");
JSONObject mJsonObject = new JSONObject();
Here it cant go xx x log, it goes into error catch.
but when i delete header and footer form json, it works. Should i use string operations to delete those or regex?
Edit:
i solved like this:
try {Log.d(TAG, "xx ");
JSONArray(sb);Log.d(TAG, "xx x");
JSONObject mJsonObject = new JSONObject();//i use this to get invidial value of json, do i need?
JSONObject jsono = new JSONObject(sb.toString());
Log.d(TAG,"jsono "+jsono.toString());
JSONArray items = jsono.getJSONArray("items");
Log.d(TAG,"items "+items);
Log.d(TAG,"items length "+items.length());
for (int i = 0; i < items.length(); i++) {
// Log.d(TAG, "xx " +mJsonObject.getString("image"));
Log.d(TAG, "string: "+items.getJSONObject(i).getString("image"));//i need image urls
}
This code does it job but sometimes it goes to error of try catch and i cant see any errors. and sometimes it takes very long time, around 1-2 minutes and mostly n0t fail in the end. why can it be?