JSON
java からの応答を作成しようとしていますservlet
。私がやったいくつかのチュートリアルを使用して
JSONObject json = new JSONObject();
JSONArray addresses = new JSONArray();
JSONObject address;
try
{
int count = 5;
for (int i=0 ; i<count ; i++)
{
address = new JSONObject();
address.put("CustomerName" , "Decepticons" + i);
address.put("Street" , "Devestator Avenue" + i);
address.put("City" , "Megatron City" + i);
address.put("Country" , "CyberTron" + i);
addresses.add(address);
}
json.put("Addresses", addresses);
}
catch (JSONException jse)
{
}
response.setContentType("application/json");
response.getWriter().write(json.toString());
出力は
{"Addresses":[{"CustomerName":"Decepticons0","Street":"Devestator Avenue0","City":"Megatron City0","Country":"CyberTron0"},{"CustomerName":"Decepticons1","Street":"Devestator Avenue1","City":"Megatron City1","Country":"CyberTron1"},{"CustomerName":"Decepticons2","Street":"Devestator Avenue2","City":"Megatron City2","Country":"CyberTron2"},{"CustomerName":"Decepticons3","Street":"Devestator Avenue3","City":"Megatron City3","Country":"CyberTron3"},{"CustomerName":"Decepticons4","Street":"Devestator Avenue4","City":"Megatron City4","Country":"CyberTron4"}]}
問題は、これを Android アプリケーションに解析しようとすると、次のようなエラーが表示されることです。
データ解析エラーorg.json.JSONException: Value <html><head><title>Apache of type java.lang.String cannot be converted to JSONObject
http://www.androidhive.info/2012/01/android-json-parsing-tutorial/の Android コード json 解析の例を使用してい ます
誰でも私の問題を解決できますか? 前もって感謝します。