如何在变量中放置带双引号,空格和括号的请求? javascript [复制]

时间:2022-02-08 07:12:16

This question already has an answer here:

这个问题在这里已有答案:

I have something like this:

我有这样的事情:

{
   "urn.getxxxx": {
       "urn.xxxx": "cxxxxx-44e9-xxxx-a91b-0000xxxx\\xxxxx\\3239750\\EO\\0\\",
       "urn.xxxx": "xxxxx",
       "urn.xxxxx": "x",
       "urn.xxxx": "2016-07-08T13:03:41+02:00"
   }
}

and i want to store it in a variable/object like var request = "{...{..}..}"; how do I do it? I have errors becouse of the {} and the doublequotes.

我想将它存储在变量/对象中,如var request =“{... {..} ..}”;我该怎么做?由于{}和双引号我有错误。

I'm a novice sorry for my poor explanation. :)

1 个解决方案

#1


0  

    var myObj = {
       "urn.getxxxx": {
           "urn.xxxx": "cxxxxx-44e9-xxxx-a91b-0000xxxx\\xxxxx\\3239750\\EO\\0\\",
           "urn.xxxx": "xxxxx",
           "urn.xxxxx": "x",
           "urn.xxxx": "2016-07-08T13:03:41+02:00"
       }
    };

var request = JSON.stringify(myObj);

Stringify JSON

#1


0  

    var myObj = {
       "urn.getxxxx": {
           "urn.xxxx": "cxxxxx-44e9-xxxx-a91b-0000xxxx\\xxxxx\\3239750\\EO\\0\\",
           "urn.xxxx": "xxxxx",
           "urn.xxxxx": "x",
           "urn.xxxx": "2016-07-08T13:03:41+02:00"
       }
    };

var request = JSON.stringify(myObj);

Stringify JSON