How to write a nested multi dimensional json object

后端 未结 4 2076
离开以前
离开以前 2021-02-05 12:56

I am studying json and i was wondering if this is the right way to write a multi dimensional json object that is nested.I wrote:

var foo = {
    \"logged_in\":tr         


        
4条回答
  •  醉话见心
    2021-02-05 13:41

    Don't write JSON. Seriously, except for simple configuration files, don't write JSON.

    You have utilities to convert objects to a JSON string in most languages (if not any).

    PHP: json_encode($array);

    Javascript: JSON.stringify( obj );

    Etc.

    Writing JSON manually often leads to syntax errors. The kind that gives you headaches until you see that missing comma or w/e. You have good tools to do this, use them. You could compare to XML, but JSON has no tool (IDEs, text editor) saying "This syntax is wrong" while you're typing it. For example, no editor will tell you that you used a single quote instead of a double.

    Just don't write JSON.

提交回复
热议问题