Tam*_*mpa 2 javascript base64 json node.js
我有一个字符串,我想解码为 json。该字符串最初是base64。当我尝试解码为杰森时,出现以下错误。
var query_string = new Buffer(bid, 'base64').toString('ascii');
console.log(query_string);
var q = JSON.parse(query_string);
{'avid': 'info@tssf.co.jp', 'crid': '20767073515', 'mabid': {'node': None, 'hod': '13', 'cid': '36', 'industry': None, 'ex': '1', 'vid1': '29', 'dow': '3'}, 'prid': {'hod': '13', 'woy': '18', 'cid': '36', 'dow': '3', 'ssp': 'adx', 'st': None, 'bt': 'firefox', 'cty': 'tokyo', 'ex': '1', 'vid2': '222', 'dt': '1', 'os': 'mac', 'vid1': '29'}, 'agid': '4547917795', 'cookieid': 'retageting:cookie', 'did': 'yahoo.com', 'validation': True}
Run Code Online (Sandbox Code Playgroud)
SyntaxError:回调时 /home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/app.js:115:16 处的 Object.parse(本机)出现意外标记(/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/node_modules /express/lib/router/index.js:272:11) 在参数 (/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/node_modules/express/lib/router/index.js:246:11) 在传递 ( /home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/node_modules/express/lib/router/index.js:253:5) 在 Router._dispatch (/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/node_modules/express /lib/router/index.js:280:4) 在 Object.handle (/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/node_modules/express/lib/router/index.js:45:10) 下一个 ( /home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/node_modules/express/node_modules/connect/lib/http.js:204:15) 在 Object.methodOverride [作为句柄] (/home/ubuntu/workspace/rtbopsConfig/rtbServers /rtbNodejsServer/node_modules/express/node_modules/connect/lib/middleware/methodOverride.js:35:5)在下一个(/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbNodejsServer/node_modules/express/node_modules/connect/lib/http .js:204:15)
JSON 格式需要双引号,而不是单引号。
还:
query_string应如下所示:
{"avid": "info@tssf.co.jp", "crid": "20767073515", "mabid": {"node": null, "hod": "13", "cid": "36", "industry": null, "ex": "1", "vid1": "29", "dow": "3"}, "prid": {"hod": "13", "woy": "18", "cid": "36", "dow": "3", "ssp": "adx", "st": null, "bt": "firefox", "cty": "tokyo", "ex": "1", "vid2": "222", "dt": "1", "os": "mac", "vid1": "29"}, "agid": "4547917795", "cookieid": "retageting:cookie", "did": "yahoo.com", "validation": true}
Run Code Online (Sandbox Code Playgroud)
我想这是一个 Python 字典,您应该使用一个库将 python 字典正确序列化为 JSON,或者如果您使用的是 Python 2.6+,只需执行以下操作:
import json
json_string = json.dumps({'test': 'test'})
Run Code Online (Sandbox Code Playgroud)
文档: http: //docs.python.org/library/json.html
| 归档时间: |
|
| 查看次数: |
6616 次 |
| 最近记录: |