Conversion between dictionary and string in JS (study notes)

1. Convert dictionary to string

1.JS code (serialization)

var args = {
    
    
	"key_1": "value_1",
	"key_2": "value_2",
	"key_3": "value_3",
	"key_4": "value_4",
}
var str = JSON.stringify(args);
console.log(str);

2. Running results

{
    
    "key_1":"value_1","key_2":"value_2","key_3":"value_3","key_4":"value_4"}

2. Convert string to dictionary

1.JS code (deserialization)

var args = {
    
    
	"key_1": "value_1",
	"key_2": "value_2",
	"key_3": "value_3",
	"key_4": "value_4",
}
var str = JSON.stringify(args);
var dic = JSON.parse(str);
console.log(dic);

2. Running results

{
    
    
    "key_1": "value_1",
    "key_2": "value_2",
    "key_3": "value_3",
    "key_4": "value_4"
}

Guess you like

Origin blog.csdn.net/weixin_47278656/article/details/129978683