我試圖解析一個複雜的json(使用Json框架),問題是json有很多嵌套的對象。花了太多的時間編程,我找不到解決方案,我的代碼聞起來,我有很多崩潰。 有什麼想法? (我沒有任何問題使用另一個JSON框架,如jsonkit或其他)需要幫助來解析複雜的JSON
這裏是json的簡化版本。
[
{
"category": {
"id": 451,
"description": "Product description",
"quantity": "3149",
"category": [
{
"category": {
"id": 115,
"description": "Product description",
"quantity": "465",
"category": [
{
"category": {
"id": 125,
"description": "Product description",
"quantity": "6"
}
},
{
"category": {
"id": 120,
"description": "Product description",
"quantity": "57",
"category": [
{
"category": {
"id": 193,
"description": "Product description",
"quantity": "27"
}
},
{
"category": {
"id": 194,
"description": "Product description",
"quantity": "14"
}
}
]
}
},
{
"category": {
"id": 446,
"description": "Product description",
"quantity": "7"
}
},
{
"category": {
"id": 132,
"description": "Product description",
"quantity": "28",
"category": [
{
"category": {
"id": 224,
"description": "Product description",
"quantity": "3"
}
},
{
"category": {
"id": 137,
"description": "Product description",
"quantity": "4"
}
}
]
}
},
{
"category": {
"id": 128,
"description": "Product description",
"quantity": "21"
}
}
]
}
},
{
"category": {
"id": 21,
"description": "Product description",
"quantity": "225",
"category": [
{
"category": {
"id": 170,
"description": "Product description",
"quantity": "1"
}
},
{
"category": {
"id": 68,
"description": "Product description",
"quantity": "45",
"category": [
{
"category": {
"id": 81,
"description": "Product description",
"quantity": "2"
}
},
{
"category": {
"id": 69,
"description": "Product description",
"quantity": "2"
}
}
]
}
}
]
}
}
]
}
},
{
"category": {
"id": 390,
"description": "Product description",
"quantity": "251",
"category": [
{
"category": {
"id": 714,
"description": "Product description",
"quantity": "0"
}
},
{
"category": {
"id": 622,
"description": "Product description",
"quantity": "22",
"category": [
{
"category": {
"id": 192,
"description": "Product description",
"quantity": "16"
}
},
{
"category": {
"id": 391,
"description": "Product description",
"quantity": "6"
}
}
]
}
},
{
"category": {
"id": 612,
"description": "Product description",
"quantity": "5"
}
},
{
"category": {
"id": 621,
"description": "Product description",
"quantity": "123",
"category": [
{
"category": {
"id": 628,
"description": "Product description",
"quantity": "25"
}
},
{
"category": {
"id": 457,
"description": "Product description",
"quantity": "3"
}
}
]
}
},
{
"category": {
"id": 720,
"description": "Product description",
"quantity": "1"
}
},
{
"category": {
"id": 188,
"description": "Product description",
"quantity": "52",
"category": [
{
"category": {
"id": 437,
"description": "Product description",
"quantity": "10"
}
},
{
"category": {
"id": 639,
"description": "Product description",
"quantity": "7"
}
},
{
"category": {
"id": 152,
"description": "Product description",
"quantity": "4",
"category": [
{
"category": {
"id": 34,
"description": "Product description",
"quantity": "3"
}
},
{
"category": {
"id": 31,
"description": "Product description",
"quantity": "1"
}
}
]
}
}
]
}
},
{
"category": {
"id": 548,
"description": "Product description",
"quantity": "3"
}
}
]
}
}]
我的目的是創建對象數組來填充數據庫,表看起來是這樣的:
idfather(父類)
idproduct
描述
量
時間戳
你沒有告訴我們你的問題到底是什麼細節。它在哪裏崩潰?是什麼原因?從json-framework返回的信息處理這些信息的代碼是什麼樣的?所有這些都是需要回答的有效問題,任何人都可以給你任何可靠的建議。 – jer 2011-03-23 15:43:13
JSON示例不是非常複雜。任何JSON庫都應該能夠處理它。所以問題不在於解析JSON,問題可能在於你走過的結果對象。但是沒有一些我們永遠不會知道的代碼。 – 2011-03-23 16:02:02
鍵值編碼呢?它基本上解決了我所有關於漫步JSON數據的問題。 – 2012-01-17 17:16:34