[問題] json的問題(解決)
有一個從http抓下來的json的字串,印出來如下(格式應該是utf8)
{"dataRecords":[{"sysId":16,
"subject":"\u6e2c\u8a66\u5132\u5b58\/\u4e0a\u50b3",
"content":"\u6e2c\u8a66\u5167\u5bb9",
"sort":0,
"createDatetime":"2012-11-28 11:41:46"
}]}
下面這句有錯
JSONObject jobj = new JSONObject(input_string);
得到以下訊息
org.json.JSONException:
Value of type java.lang.String cannot be converted to JSONObject
我想請問用httpclient抓下來的字串要怎麼處理jsonobject才認得?
直拉寫在java裡的可以吃,但是直接由http抓下來的就會有問題。
--
結果是BOM的問題,我試過substring(3),但還是一樣exception
改用
int index = jsonstring.indexOf("{");
jsonstring = jsonstring.substring(index);
就可以了。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.241.124.234
※ 編輯: tsaiminghan 來自: 111.241.124.234 (12/20 02:11)
推
12/20 16:41, , 1F
12/20 16:41, 1F
推
12/21 23:34, , 2F
12/21 23:34, 2F
→
01/05 15:49, , 3F
01/05 15:49, 3F