如何使用Javascript将JSON字符串转换为具有其他结构的新JSON对象

时间:2017-07-23 06:43:15

标签: javascript json

json字符串无法通过javascript读取帮助我将其转换为javascript Json对象

{
  text: {
    name: "ROOT"
  },
  HTMLclass: "blue",
  image: "images/no_member.png",
  children: [
    {
      connectors: {
        style: {
          stroke: "#000000"
        }
      },
      text: {
        name: "SAYED"
      },
      HTMLclass: "blue",
      image: "images/no_member.png",

    },
    {
      connectors: {
        style: {
          stroke: "#000000"
        }
      },
      text: {
        name: "DIDAR"
      },
      HTMLclass: "blue",
      image: "images/no_member.png",

    }
  ]
}

2 个答案:

答案 0 :(得分:1)

JSON.parse()可能会回答,你应该在""中包围密钥。 但是JSON(JavaScript Object Notation)意味着"符号类似Javascript Object"。 所以最初想想。喜欢以下;

    var obj = {
        text: {
            name: "ROOT"
        },
        HTMLclass: "blue",
        image: "images/no_member.png",
        children: [
            {
                connectors: {
                    style: {
                        stroke: "#000000"
                    }
                },
                text: {
                    name: "SAYED"
                },
                HTMLclass: "blue",
                image: "images/no_member.png",

            },
            {
                connectors: {
                    style: {
                        stroke: "#000000"
                    }
                },
                text: {
                    name: "DIDAR"
                },
                HTMLclass: "blue",
                image: "images/no_member.png",

            }
        ]
    };
    console.log(obj);

谢谢。

答案 1 :(得分:-1)

你想要JSON.parse()。

有关详细信息,请参阅JSON