[英]Json Array Parsing issue
``我有一個Json Array作為響應,例如:
[
{
"status": "Active",
"entityName": "fghgfhfghfgh",
"entityCode": 14,
"children": [],
"attributes": [
{
"attributeValue": "500 michigan ave"
}
],
"deviceList": [],
"entityId": "64eab9299eed9455b3683da074cf175c",
"customerId": 2006546,
"type": "7dad308f82b41e02fe8959c05b631bd7"
}
,
{
"status": "Active",
"entityName": "ghghhguyutgh6re58rrt",
"entityCode": 13,
"children": [],
"attributes": [
{
"attributeValue": "500 michigan ave"
}
],
"deviceList": [],
"entityId": "912eff0613fa140c100af435c033e195",
"customerId": 2006546,
"type": "7dad308f82b41e02fe8959c05b631bd7"
}
]
我想將此json分成兩個
{“ status”:“活動”,“ entityName”:“ fghgfhfghfgh”,“ entityCode”:14,“ children”:[],“ attributes”:[{“ attributeValue”:“ 500 michigan ave”}],“ deviceList “:[],” entityId“:” 64eab9299eed9455b3683da074cf175c“,” customerId“:2006546,” type“:” 7dad308f82b41e02fe8959c05b631bd7“}
我正在使用GSON和simplejson,當我嘗試刪除定界符([和])時,json格式不正確。是否有更好的方法將json數組按照分為兩個或更多json字符串json響應即將到來。
有什么原因不能解析整個數組,然后分別遍歷/處理每個元素?
僅刪除括號會使JSON無效,並且以逗號分隔將是不可靠的。 解析器的存在是為了找出在何處分割數組並將每個元素變成一個對象。
假設您已經定義了一些數據結構,以便在分解數組后保留單個元素,那么您應該能夠將數組解析為其中的一個列表,並根據需要逐步遍歷(或挑選一個)。
之后,您可以對數據進行任何操作(包括將其格式化回JSON)。 不過,我絕對建議使用適當的解析器來分解數組。 它會更簡單,更可靠,並且應該可以工作,除非您有嚴重的性能問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.