簡體   English   中英

我可以將PHP變量插入JSON字符串嗎?

[英]Can I insert PHP variables into a JSON string?

我正在使用REST API將屬性POST到使用json的人。 我的請求正文如下所示:

$requestBody = '

{
    "attribute": {
        "@id": "",
        "@uri": "",
        "person": {
            "@id": "222",
            "@uri": "https://api_name_removed.com/v1/People/222"
        },
        "attributeGroup": {
            "@id": "",
            "@uri": "",
            "name": null,
            "attribute": {
                "@id": "2404",
                "@uri": "",
                "name": null
            }
        },
        "lastUpdatedDate": null
    }
}';

如何將人員ID,人員uri和屬性ID更改為已經存儲的變量?

$requestBody = '

{
    "attribute": {
        "@id": "' . $id . '",
        "@uri": "' . $uri . '",
        "person": {
            "@id": "222",
            "@uri": "https://api_name_removed.com/v1/People/222"
        },
        "attributeGroup": {
            "@id": "",
            "@uri": "",
            "name": null,
            "attribute": {
                "@id": "2404",
                "@uri": "",
                "name": null
            }
        },
        "lastUpdatedDate": null
    }
}';
$requestBody = sprintf('
{
    "attribute": {
        "@id": "%u",
        "@uri": "%s",
        "person": {
            "@id": "222",
            "@uri": "https://api_name_removed.com/v1/People/222"
        },
        "attributeGroup": {
            "@id": "",
            "@uri": "",
            "name": null,
            "attribute": {
                "@id": "2404",
                "@uri": "",
                "name": null
            }
        },
        "lastUpdatedDate": null
    }
}', $id, $uri);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM