var body = JSON.stringify(params);
// Create an XMLHttpRequest 'POST' request w/ an optional callback handler
req.open('POST', '/rpc', async);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", body.length);
req.setRequestHeader("Connection", "close");
if (async) {
req.onreadystatechange = function() {
if(req.readyState == 4 && req.status == 200) {
var response = null;
try {
response = JSON.parse(req.responseText);
} catch (e) {
response = req.responseText;
}
callback(response);
}
};
}
// Make the actual request
req.send(body);
----在服务器端----
class RPCHandler(BaseHandler):
'''@user_required'''
def post(self):
RPCmethods = ("UpdateScenario", "DeleteScenario")
logging.info(u'body ' + self.request.body)
args = simplejson.loads(self.request.body)
---- 在服务器日志正文 %5B%22UpdateScenario%22%2C%22c%22%2C%224.5%22%2C%2230frm%22%2C%22Refinance%22%2C%22100000%22% 获取以下错误2C%22740%22%2C%2294538%22%2C%2250000%22%2C%22owner%22%2C%22sfr%22%2C%22Fremont%22%2C%22CA%22%5D=
无法解码 JSON 对象:第 1 行第 0 列(字符 0):回溯(最后一次调用):文件“/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py”,第 703 行,调用 handler.post(*groups) 文件“/base/data/home/apps/s~mortgageratealert-staging/1.357912751535215625/main.py”,第 418 行,在 post args = json.loads(self.request .body) 文件 "/base/python_runtime/python_lib/versions/1/simplejson/ init.py”,第 388 行,在负载中返回 _default_decoder.decode(s) 文件“/base/python_runtime/python_lib/versions/1/simplejson/decoder.py”,第 402 行,在解码 obj 中,end = self.raw_decode(s , idx=_w(s, 0).end()) 文件“/base/python_runtime/python_lib/versions/1/simplejson/decoder.py”,第 420 行,raw_decode 引发 JSONDecodeError(“无法解码 JSON 对象” , s, idx) JSONDecodeError: No JSON object could be decoded: line 1 column 0 (char 0)
---萤火虫显示以下---
参数 application/x-www-form-urlencoded ["UpdateScenario","c","4....
源 ["UpdateScenario","c","4.5","30frm","Refinance","100000" ,"740","94538","50000","所有者","sfr","弗里蒙特","CA"]
根据萤火虫报告和日志显示 self.request.body 符合预期。但是 simplejson 加载不喜欢它。
请帮忙!