Home  >  Q&A  >  body text

javascript - Webstorm creates json file problem

In Figure 1, when there are no variables, the file is OK

In Figure 2, when something like a={} appears, an error is reported. What I actually want is something like this
, like this, as follows

巴扎黑巴扎黑2692 days ago1121

reply all(2)I'll reply

  • 漂亮男人

    漂亮男人2017-06-05 11:15:00

    json has strict requirements on the format. You cannot add = directly to the json file. You must follow the format of "key":.... You can assign the obtained json object to a variable in js

    reply
    0
  • 漂亮男人

    漂亮男人2017-06-05 11:15:00

    The json format is wrong. You can copy this object to a js file and use JSON.stringify to convert it and then copy it to the json file:
    var obj={a:1,b:2,'c':[1 ,2],'d':{c:[2,34,4]}}
    JSON.stringify(obj)==>"{"a":1,"b":2,"c":[ 1,2],"d":{"c":[2,34,4]}}"

    reply
    0
  • Cancelreply