我想把一个数组转义成JSON,然后保存到COOKIE里。数组结构:
array(2) {
  [0]=>
  array(4) {
    ["object_key"]=>
    string(10) "template_1"
    ["object_desc"]=>
    string(28) ""蓝色"用户风格(默认)"
    ["custom_object_value"]=>
    string(1) "1"
    ["priority"]=>
    int(1)
  }
  [1]=>
  array(4) {
    ["object_key"]=>
    string(10) "template_2"
    ["object_desc"]=>
    string(20) ""红色"用户风格"
    ["custom_object_value"]=>
    string(1) "0"
    ["priority"]=>
    int(0)
  }
}用json_encode()转义上面数组:
[{"object_key":"template_1","object_desc":"\"\u84dd\u8272\"\u7528\u6237\u98ce\u683c(\u9ed8\u8ba4)","custom_object_value":"1","priority":1},{"object_key":"template_2","object_desc":"\"\u7ea2\u8272\"\u7528\u6237\u98ce\u683c","custom_object_value":"0","priority":0}]
然后将这个字符串保存到Cookie里但是在JS里取这个COOKIE的时候,值又变成了:
%5B%7B%22object_key%22%3A%22template_1%22%2C%22object_desc%22%3A%22%5C%22%5Cu84dd%5Cu8272%5C%22%5Cu7528%5Cu6237%5Cu98ce%5Cu683c%28%5Cu9ed8%5Cu8ba4%29%22%2C%22custom_object_value%22%3A%221%22%2C%22priority%22%3A1%7D%2C%7B%22object_key%22%3A%22template_2%22%2C%22object_desc%22%3A%22%5C%22%5Cu7ea2%5Cu8272%5C%22%5Cu7528%5Cu6237%5Cu98ce%5Cu683c%22%2C%22custom_object_value%22%3A%220%22%2C%22priority%22%3A0%7D%5D
把这个字符串用站长工具“URLDecode”解码,确实能解出来转义后的JSON字符串。问题是:
1、数组转义成JSON字符串的时候,为什么中文都变成了类似“u84dd\u8272”的串?为什么还多了好多的“\”?这是什么编码方式?该怎么解析?
2、为什么用JS读COOKIE的时候,它又变成了另外一种编码?这又是什么编码方式?该怎么解析?
3、可以用unescape()函数解析JS从cookie里取的这个值吗?谢谢!