JSON递归数据~PHP CODE

时间:2017-05-16 10:29:52

标签: php json

有人可以帮我想一个智能算法吗?

问题

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": {
                "ref": 2
            }
        },
        "Children": null
    }
}

无论如何,现在的问题是它包含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数据
  • 如何复制它,但每个值都设置值Childrennull 时间?

我希望有人知道如何做到这一点,因为我无法想到一个聪明的方法......

0 个答案:

没有答案