小编vin*_*pux的帖子

Python json.loads不起作用

我一直在试图弄清楚如何在Python中加载JSON对象.

   def do_POST(self):
    length = int(self.headers['Content-Length'])
    decData = str(self.rfile.read(length))
    print decData, type(decData)
    "{'name' : 'journal2'}" <type 'str'>
    postData = json.loads(decData)
    print postData, type(postData)
    #{'name' : 'journal2'} <type 'unicode'>
    postData = json.loads(postData)
    print postData, type(postData)
    # Error: Expecting property name enclosed in double quotes
Run Code Online (Sandbox Code Playgroud)

我哪里错了?

错误代码(JScript):

var data = "{'name':'journal2'}";
var http_request = new XMLHttpRequest();
http_request.open( "post", url, true );
http_request.setRequestHeader('Content-Type', 'application/json');
http_request.send(data);
Run Code Online (Sandbox Code Playgroud)

True Code(JScript):

var data = '{"name":"journal2"}';
var http_request = new XMLHttpRequest();
http_request.open( "post", url, true );
http_request.setRequestHeader('Content-Type', 'application/json'); …
Run Code Online (Sandbox Code Playgroud)

python json

10
推荐指数
2
解决办法
3万
查看次数

标签 统计

json ×1

python ×1