The json in json lint JSONArrayを間違って使用している人がいます。私はJSONObjectを使用しています。値{ "TopLeftCorner":{ "経度":0.0、 "緯度":100.0}、 "TopRightCorner":{ "経度HttpResponseの結果を解析しようとしたときのJSONException
HttpResponse response = httpClient.execute(httpGet);
String json_string = EntityUtils.toString(response.getEntity(), "UTF-8");
updateBoundaries(new JSONObject(json_string));
System.out.println(json_string);
は私にエラー
org.json.JSONExceptionを取得します":100.0、" Latitude ":100.0}、" BottomLeftCorner ":{"経度 ":0.0、" Latitude ":0.0}、" BottomRightCorner ":{"経度 ":100.0、" Latitude ":0.0}} .lang.StringをJSONObjectに変換することはできません
ただし、JSONをJSONのLintにコピーすると完全に問題ありません。私はそれを解析しようとしている文字列を印刷するとき、それは
のように見える "{\" TopLeftCorner \ ":{\" 経度\ ":0.0、\" 緯度\ ":100.0}、\" TopRightCorner \ ":経度\":100.0、\ "Latitude \":100.0} \ "BottomLeftCorner \":\ "経度\":0.0 \ "Latitude \":0.0} \ "BottomRightCorner \": {\ "経度\":100.0、 "緯度\" \:0.0}}」
それは許容JSONにする必要がありますが、JSONObjectが何らかの理由でそれを解析することができないように見えます。どうしたの?
編集:スタックトレース
W/System.err: org.json.JSONException: Value {"TopLeftCorner":{"Longitude":0.0,"Latitude":100.0},"TopRightCorner":{"Longitude":100.0,"Latitude":100.0},"BottomLeftCorner":{"Longitude":0.0,"Latitude":0.0},"BottomRightCorner":{"Longitude":100.0,"Latitude":0.0}} of type java.lang.String cannot be converted to JSONObject
W/System.err: at org.json.JSON.typeMismatch(JSON.java:111)
W/System.err: at org.json.JSONObject.<init>(JSONObject.java:160)
W/System.err: at org.json.JSONObject.<init>(JSONObject.java:173)
W/System.err: at com.example.chan.locationapiapp.MainActivity$1$1.run(MainActivity.java:62)
W/System.err: at java.lang.Thread.run(Thread.java:761)
'toString()' dはすでに有効なJSON文字列です。 –
注:Apache HTTPはAndroidでは非推奨です。ボレーはJSONリクエストを行うことができます。 https://developer.android.com/training/volley/request.html#request-json –
ありがとう!私はそれを代わりに使用しようとします。 JSONエラーを処理するのはうんざりです。もしVollyが私にとってそれを行うことができれば、それはずっと良いでしょう。 –