2016-12-03 46 views
-2

我的數據是這樣的回報率在結果集中如何將結果集數據轉換爲我的對象。下面是數據的格式

[[{hostItemId=44, userId=1, title=This is the title 29 for skill(cleaning) for paid items..., description=This is the description 29 for skill (cleaning) for paid items..., isFree=false, price=42.0, requestCount=2, categoryId=3, attachmentUrl=1478684543988image.jpg, currencySymbol=20B9, hostItemStatus=3, shareType=1}, {hostItemId=24, userId=1, title=This is title 15 for skill (spring chores)..., description=This is the description 15 for skill (spring chores)..., isFree=true, price=null, requestCount=2, categoryId=3, attachmentUrl=1478672337661image.jpg, currencySymbol=null, hostItemStatus=3, shareType=1}]] 
+0

歡迎來到Stack Overflow!看起來你正在尋求作業幫助。雖然我們本身沒有任何問題,但請觀察這些[應做和不應該](http://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions/338845#338845),並相應地編輯您的問題。 –

回答

1

你必須給JSON數據是錯誤的。它會拋出一個錯誤。 Json數據的正確語法是var jsondata = [ [ { "hostItemId": 44, "userId": 1, "title": "This is the title 29 for skill(cleaning) for paid items...", "description": "This is the description 29 for skill (cleaning) for paid items...", "isFree": false, "price": 42, "requestCount": 2, "categoryId": 3, "attachmentUrl": "1478684543988image.jpg", "currencySymbol": "20B9", "hostItemStatus": 3, "shareType": 1 }, { "hostItemId": 24, "userId": 1, "title": "This is title 15 for skill (spring chores)...", "description": "This is the description 15 for skill (spring chores)...", "isFree": true, "price": null, "requestCount": 2, "categoryId": 3, "attachmentUrl": "1478672337661image.jpg", "currencySymbol": null, "hostItemStatus": 3, "shareType": 1 } ] ]

之後,您可以將此json字符串解碼爲您的對象。

// Creating a JSONObject from a String 
JSONObject nodeRoot = new JSONObject(jsondata); 

// Creating a sub-JSONObject from another JSONObject 
JSONObject nodeStats = nodeRoot.getJSONObject("stats"); 
相關問題