JSON递归数据~PHP代码
有人能帮我想出一个聪明的算法吗 问题 JSON数据看起来有点像这样(无法提供真实数据:/): 无论如何,现在的问题是它包含JSON递归数据~PHP代码,php,json,Php,Json,有人能帮我想出一个聪明的算法吗 问题 JSON数据看起来有点像这样(无法提供真实数据:/): 无论如何,现在的问题是它包含ref,后面有一个值。上面的JSON应该是这样的: { "$id": "1", "Start": 1000, "End": 1200, "Account": { "$id": "2", "id": "af51f511-e851-4d01-808b-2fa3c070d3ad", "aLotMoreI
ref
,后面有一个值。上面的JSON应该是这样的:
{
"$id": "1",
"Start": 1000,
"End": 1200,
"Account": {
"$id": "2",
"id": "af51f511-e851-4d01-808b-2fa3c070d3ad",
"aLotMoreInfo": "cool",
"Parents": {
"$id": "3",
"id": "73d7a1f1-82e8-4a7e-bccb-838a251e1a38",
"aLotMoreInfo": "notcool",
"Parents": null,
"Children": {
"$id": "2",
"id": "af51f511-e851-4d01-808b-2fa3c070d3ad",
"aLotMoreInfo": "cool",
"Parents": {
"$id": "3",
"id": "73d7a1f1-82e8-4a7e-bccb-838a251e1a38",
"aLotMoreInfo": "notcool",
"Parents": null,
"Children": null
},
"Children": null
},
"Children": null
}
}
}
我需要知道两件事:
- 如何轻松获取之前已经声明过的JSON数据
- 如何复制它,但将值
设置为Children
每一个 时间null
我希望有人知道这样做的好方法,因为我真的想不出一个聪明的方法…要轻松访问数据,您可以使用上一个过程-只要将它们存储在
数组中通过id
-如果您有足够的内存的话。您只想将多级数组更改为第一个版本中的数组吗?将ref
作为键,而不是值。
{
"$id": "1",
"Start": 1000,
"End": 1200,
"Account": {
"$id": "2",
"id": "af51f511-e851-4d01-808b-2fa3c070d3ad",
"aLotMoreInfo": "cool",
"Parents": {
"$id": "3",
"id": "73d7a1f1-82e8-4a7e-bccb-838a251e1a38",
"aLotMoreInfo": "notcool",
"Parents": null,
"Children": {
"$id": "2",
"id": "af51f511-e851-4d01-808b-2fa3c070d3ad",
"aLotMoreInfo": "cool",
"Parents": {
"$id": "3",
"id": "73d7a1f1-82e8-4a7e-bccb-838a251e1a38",
"aLotMoreInfo": "notcool",
"Parents": null,
"Children": null
},
"Children": null
},
"Children": null
}
}
}