VaR STR = '{"dir": "kunhony", "Param": "ARCHIVE"}'; var AAA = JSON. parse (STR); console. log (AAA. param );
The above code is correct, but if you change var STR = '{"dir": "kunhony", "Param": "ARCHIVE"}';: vaR STR = "{'dir': 'kunhony', 'param': 'archive'}"; an error is reported in the code. The specific cause has been hard to understand. I have time to study the node. js source code. Does anyone know? The Code is as follows:
VaR STR = "{'dir': 'kunhony', 'param': 'archive'}"; var AAA = JSON. parse (STR); console. log (AAA. param );
VaR DATA = {dir: 'kunhony', Param: 'archive'}; var STR = JSON. stringify (data); console. log (STR); var AAA = JSON. parse (STR); console. log (AAA. param );
The above code can be used, because JSON. stringify (data); converts the object back to the {"dir": "kunhony", "Param": "ARCHIVE"} string.
Note: this problem also exists after testing on the browser. It seems that in JSON, double quotation marks cannot be used for string. Now, let's take a look at this.