我的客户代码:
var http = new XMLHttpRequest();
var url = "http://localhost:8000/recData";
var params = JSON.stringify({json: screen_keywords});
console.log(params);
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function() {
//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);
我的服务器:
^{pr2}$结果是:
'"{\\"json\\":[{\\"id\\":\\"1453-HCI-user-human-computer-interaction\\",\\"x_cordinate\\":395.9217224121094,\\"y_cordinate\\":729.04296875,\\"keyword\\":\\"user-human-computer-interaction\\",\\"radius\\":\\"70.359375\\",\\"obj_rel\\":false,\\"sub_rel\\":false},{\\"id\\":\\"4044-HCI-user-design\\",\\"x_cordinate\\":544.33837890625,\\"y_cordinate\\":773.467529296875,\\"keyword\\":\\"user-design\\",\\"radius\\":\\"50.359375\\",\\"obj_rel\\":false,\\"sub_rel\\":false},{\\"id\\":\\"668-HCI-user-experience\\",\\"x_cordinate\\":328.0223083496094,\\"y_cordinate\\":460.09271240234375,\\"keyword\\":\\"user-experience\\",\\"radius\\":\\"73.703125\\",\\"obj_rel\\":false,\\"sub_rel\\":false},{\\"id\\":\\"2714-HCI-user-enjoyment\\",\\"x_cordinate\\":562.9501342773438,\\"y_cordinate\\":268.96636962890625,\\"keyword\\":\\"user-enjoyment\\",\\"radius\\":\\"70.359375\\",\\"obj_rel\\":false,\\"sub_rel\\":false},{\\"id\\":\\"2659-ip-ip-TCP\\",\\"x_cordinate\\":648.444091796875,\\"y_cordinate\\":813.05712890625,\\"keyword\\":\\"ip-TCP\\",\\"radius\\":\\"41\\",\\"obj_rel\\":true,\\"sub_rel\\":false},{\\"id\\":\\"1022-service-ecosystem-trust\\",\\"x_cordinate\\":743.697509765625,\\"y_cordinate\\":848.6085205078125,\\"keyword\\":\\"trust\\",\\"radius\\":\\"38.3359375\\",\\"obj_rel\\":false,\\"sub_rel\\":false},{\\"id\\":\\"1916-ip-ip-management\\",\\"x_cordinate\\":750.01123046875,\\"y_cordinate\\":681.5203247070312,\\"keyword\\":\\"ip-management\\",\\"radius\\":\\"85.0390625\\",\\"obj_rel\\":true,\\"sub_rel\\":true},{\\"id\\":\\"1769-service-ecosystem-service-design\\",\\"x_cordinate\\":653.7368774414062,\\"y_cordinate\\":903.925537109375,\\"keyword\\":\\"service-design\\",\\"radius\\":\\"53.0078125\\",\\"obj_rel\\":false,\\"sub_rel\\":true},{\\"id\\":\\"4516-HCI-user-fun\\",\\"x_cordinate\\":562.857177734375,\\"y_cordinate\\":884.592529296875,\\"keyword\\":\\"user-fun\\",\\"radius\\":\\"41\\",\\"obj_rel\\":false,\\"sub_rel\\":true},{\\"id\\":\\"2291-HCI-user-usability\\",\\"x_cordinate\\":436.70556640625,\\"y_cordinate\\":878.2095947265625,\\"keyword\\":\\"user-usability\\",\\"radius\\":\\"58.3515625\\",\\"obj_rel\\":false,\\"sub_rel\\":true}]}"'
我将json发送到服务器端,但无法在服务器端解码。因为我想用它作为一个列表,所以我可以通过访问每个对象在python端使用for循环。请告诉我怎么修理这个。我的结果变量当前看起来像这样,如代码片段中所示。我们将非常感谢您的帮助。在
您正在尝试重新编码JSON字符串。您需要使用^{} 代替:
相关问题 更多 >
编程相关推荐