[英]parsing URL in String from JSON
1)我有一個JSON文件:
{
"serverURI":"http://localhost:8080/PocketUNI_API/serverURLs",
"newsURI":"http://localhost:8080/gateway/rss/rss.xml",
"modulesURI":"http://localhost:8080/PocketUNI_API/modules"
}
2)我需要以String格式在Java客戶端上獲取URL。
String json = jsonReceiver.makeHttpRequest(URL_SERVER, "GET", params);
JSONArray uris = new JSONArray(json);
Receiver工作正常,json顯示收到的正確字符串,但是當它轉到使用JSONArray解析時會拋出錯誤
org.json.JSONException: Value {"serverURI":"http:\/\/192.168.0.... of type org.json.JSONObject cannot be converted to JSONArray.
問題:如何使用URL值解析json?
你沒有得到JSONArray
而是JSONObject
。
JSONObject uris = new JSONObject(json);
json
是一個json對象而不是數組,這就是你得到錯誤的原因。 數組將用[
和]
和{
和}
對象包裝。
JSONObject uris = new JSONObject (json);
您必須使用JSONObject
而不是JSONArray
。
JSONObject uris = new JSONObject(json);
在您的代碼中,只需將JSONArray替換為JSONobject
JSONObject uris = new JSONObject(json);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.