某种JSON的JSON.Stringify()使其无效 - node.js

时间:2013-09-18 14:27:50

标签: json node.js

当我尝试将以下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有效?

0 个答案:

没有答案