如何将json从文本转换为有效的字符串

时间:2013-11-10 08:45:19

标签: json converter

我有json的文本文件,我喜欢将它们嵌入到我的案例cpp中的字符串中 有没有任何工具或实用程序来做到这一点? 例如,我有这个长的json,我喜欢和有效的弦乐一起演唱。

{
    "rigidBodies": [
        {
            "name": "car_test_mapping",
            "imagePath": "car_body_test.png",
            "origin": {
                "x": 0,
                "y": 0
            },
            "polygons": [
                [
                    {
                        "x": 0.782500028610229,
                        "y": 0.21000000834465
                    },
                    {
                        "x": 0.727500081062317,
                        "y": 0.340000003576279
                    },
                    {
                        "x": 0.179999947547913,
                        "y": 0.422500014305115
                    },
                    {
                        "x": 0.179999947547913,
                        "y": 0.260000020265579
                    }
                ],
                [
                    {
                        "x": 0.179999947547913,
                        "y": 0.260000020265579
                    },
                    {
                        "x": 0.00249993801116943,
                        "y": 0.265000015497208
                    },
                    {
                        "x": 0,
                        "y": -0.00499993562698364
                    },
                    {
                        "x": 0.992500066757202,
                        "y": -0.00499993562698364
                    },
                    {
                        "x": 0.990000009536743,
                        "y": 0.1875
                    },
                    {
                        "x": 0.782500028610229,
                        "y": 0.21000000834465
                    }
                ]
            ],
            "circles": [],
            "shapes": [
                {
                    "type": "POLYGON",
                    "vertices": [
                        {
                            "x": 0.00249993801116943,
                            "y": 0.265000015497208
                        },
                        {
                            "x": 0.179999947547913,
                            "y": 0.260000020265579
                        },
                        {
                            "x": 0.179999947547913,
                            "y": 0.422500014305115
                        },
                        {
                            "x": 0.727500081062317,
                            "y": 0.340000003576279
                        },
                        {
                            "x": 0.782500028610229,
                            "y": 0.21000000834465
                        },
                        {
                            "x": 0.990000009536743,
                            "y": 0.1875
                        },
                        {
                            "x": 0.992500066757202,
                            "y": -0.00499993562698364
                        },
                        {
                            "x": 0,
                            "y": -0.00499993562698364
                        }
                    ]
                }
            ]
        }
    ],
    "dynamicObjects": []
}

1 个答案:

答案 0 :(得分:1)

您必须使用JSON.stringify.see documentation