0

当我尝试对以下 JSON 进行字符串化时,字符串化的 JSON 变得无效:

{
    "header": {
        "messageId": "6771ec15-7e97-4e74-9056-d8dc3302e034",
        "messageDate": "2013-09-18T09:53:06.864Z"
    },
    "body": {
        "requestId": "6771ec15-7e97-4e74-9056-d8dc3302e034",
        "ownerId": "44c14558-985b-4fab-9f06-d57f1f56b946",
        "uri": "vm/lunacloud/eu-central/xsmall",
        "metadata": {
            "name": "CNWB0FE6_7A16_CEE9_754D_B4C1F2037411",
            "description": "LunaCloud xSmall Machine with Ubuntu 12.04",
            "workloadId": "08ee63c2-3b71-4865-9f58-6b33dfef4f1e",
            "transactionId": "abca4f3d-fcec-4df4-8867-cb380ade2c8b"
        },
        "parameters": {
            "imageUri": "image/lunacloud/eu-central/ubuntu-12.04-x86_64-fr",
            "action": "vm.create",
            "instanceId": "0119d5f1-cf66-406c-a820-768fd8b85020",
            "vm_providerResourceId": "{\"cpuCount\":\"1\",\"cpupower\":\"1500\",\"ramsize\":\"1\",\"bandwidth\":\"100\",\"publicIPCount\":\"1\",\"localStorage\":\"true\",\"disksize\":\"50\"}",
            "zone": "EU-Central",
            "username": "root",
            "image_providerResourceId": "ubuntu-12.04-x86_64-FR"
        },
        "action": "vm.create",
        "resourceUri": "vm/lunacloud/eu-central/xsmall",
        "resourceType": "vm",
        "provider": "lunacloud",
        "region": "eu-central",
        "providerResourceId": "{\"cpuCount\":\"1\",\"cpupower\":\"1500\",\"ramsize\":\"1\",\"bandwidth\":\"100\",\"publicIPCount\":\"1\",\"localStorage\":\"true\",\"disksize\":\"50\"}",
        "connector": "lunaCloud.compute",
        "_id": "6771ec15-7e97-4e74-9056-d8dc3302e034",
        "created": "2013-09-18T09:52:42.731Z",
        "updated": "2013-09-18T09:52:42.731Z",
        "requestStatus": "in-progress",
        "results": {
            "providerInstanceId": "0119d5f1-cf66-406c-a820-768fd8b85020",
            "password": "436zfyEVS",
            "publicIpAddress": "185.12.116.56",
            "privateIpAddress": "10.158.101.2",
            "instanceStatus": "created"
        }
    },
    "routingKey": "apiv2.one"
}

在 stringify 之后,上面的 JSON 就变成了

{
    "header": {
        "messageId": "6771ec15-7e97-4e74-9056-d8dc3302e034",
        "messageDate": "2013-09-18T09:53:06.864Z"
    },
    "body": {
        "requestId": "6771ec15-7e97-4e74-9056-d8dc3302e034",
        "ownerId": "44c14558-985b-4fab-9f06-d57f1f56b946",
        "uri": "vm/lunacloud/eu-central/xsmall",
        "metadata": {
            "name": "CNWB0FE6_7A16_CEE9_754D_B4C1F2037411",
            "description": "LunaCloud xSmall Machine with Ubuntu 12.04",
            "workloadId": "08ee63c2-3b71-4865-9f58-6b33dfef4f1e",
            "transactionId": "abca4f3d-fcec-4df4-8867-cb380ade2c8b"
        },
        "parameters": {
            "imageUri": "image/lunacloud/eu-central/ubuntu-12.04-x86_64-fr",
            "action": "vm.create",
            "instanceId": "0119d5f1-cf66-406c-a820-768fd8b85020",
            "vm_providerResourceId": "{"cpuCount":"1","cpupower":"1500","ramsize":"1","bandwidth":"100","publicIPCount":"1","localStorage":"true","disksize":"50"}",
            "zone": "EU-Central",
            "username": "root",
            "image_providerResourceId": "ubuntu-12.04-x86_64-FR"
        },
        "action": "vm.create",
        "resourceUri": "vm/lunacloud/eu-central/xsmall",
        "resourceType": "vm",
        "provider": "lunacloud",
        "region": "eu-central",
        "providerResourceId": "{"cpuCount":"1","cpupower":"1500","ramsize":"1","bandwidth":"100","publicIPCount":"1","localStorage":"true","disksize":"50"}",
        "connector": "lunaCloud.compute",
        "_id": "6771ec15-7e97-4e74-9056-d8dc3302e034",
        "created": "2013-09-18T09:52:42.731Z",
        "updated": "2013-09-18T09:52:42.731Z",
        "requestStatus": "in-progress",
        "results": {
            "providerInstanceId": "0119d5f1-cf66-406c-a820-768fd8b85020",
            "password": "436zfyEVS",
            "publicIpAddress": "185.12.116.56",
            "privateIpAddress": "10.158.101.2",
            "instanceStatus": "created"
        }
    },
    "routingKey": "apiv2.one"
}

错误发生在属性 providerResourceId。即使在字符串化或解析之后如何保持 JSON 有效?

4

0 回答 0