私が使用したコードはlocalhostで完全に機能しますが、文字列からJSONオブジェクトへの解析中に表示されているエラーを解析する際に、Webサーバーでそれを実行しようとしました
私のJSONパーサーコードは
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "utf-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
Log.d("converted result", json);
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject("{" + json +"}");
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
LogCat情報
01-29 11:45:53.556: D/Search keyword:(921): saint louis
01-29 11:45:57.288: D/converted result(921):
connected{"products":[{"pid":"406355","name":"852610 SOUTHCOUNTYMALL"},{"pid":"406356","name":"852611 SOUTHCOUNTYMALL"},{"pid":"406357","name":"852612 SOUTHCOUNTYMALL"}],"success":1}
01-29 11:45:57.288: E/JSON Parser(921): Error parsing data org.json.JSONException: Expected ':' after connected at character 11 of {connected{"products":[{"pid":"406355","name":"852610 SOUTHCOUNTYMALL"},{"pid":"406356","name":"852611 SOUTHCOUNTYMALL"},{"pid":"406357","name":"852612 SOUTHCOUNTYMALL"}],"success":1}
01-29 11:45:57.288: E/JSON Parser(921): }