Я хочу проанализировать ответ JSON с URL, но всегда получаю сообщение об ошибке. Я так старался, но не смог решить проблему. Пожалуйста, предложите мне исправить ошибки.
Мой ответ JSON:
{
"classification": {
"relevancyScore": 999,
"searchUrl": {
"value": "http://www.bizrate.com/iphone-cases/index__rf--af1__af_assettype_id--10__af_creative_id--6__af_id--50085__af_placement_id--1.html"
}
},
[.. hundreds of lines removed ..]
Мой код:
public class test extends Activity {
/** Called when the activity is first created. */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView lv = (ListView)findViewById(R.id.listView1);
lv.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, this.fetchTwitterPublicTimeline()));
}
public ArrayList<String> fetchTwitterPublicTimeline()
{
ArrayList<String> listItems = new ArrayList<String>();
try {
URL twitter = new URL(
"http://catalog.bizrate.com/services/catalog/v1/us/product?publisherId=50085&placementId=1&categoryId=1&keyword=iphone+cases&start=0&results=10&sort=relevancy_desc&brandId=&attFilter=&zipCode=90291&biddedOnly=&minRelevancyScore=100&apiKey=58f536aa2fab110bbe0da501150bac1e&format=json");
URLConnection tc = twitter.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
tc.getInputStream()));
String line;
String str;
while ((line = in.readLine()) != null) {
//str = line.substring(line.indexOf("{"), line.lastIndexOf(line));
//str = line.replaceAll("BIZRATE.Suggest.callback(", null);
//str = str.replaceAll(")", null);
//System.out.println("SubString:"+str);
JSONArray ja = new JSONArray(line);
for (int i = 0; i < ja.length(); i++) {
JSONObject jo = (JSONObject) ja.get(i);
System.out.println("value----"+jo.getJSONObject("product"));
//listItems.add(jo.getString("suggestions"));
}
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return listItems;
}
}
Я должен проанализировать информацию обо всех продуктах.