[英]JSON - how to convert plain format into json format?
从worklight适配器调用后,我得到了响应。
{“ text”:“ {\\ n \\” responseCode \\“:\\” 00 \\“,\\ n \\” responseMsg \\“:空,\\ n \\” buildFromAccountsMap \\“:{\\ n \\” 1000071000005844 D \\“:\\ “ 1000071000005844 \\”,\\ n \\“ 1000791000030636 D \\”:\\“ 1000791000030636 \\”,\\ n \\“ 1001911000036935 D \\”:\\“ 1001911000036935 \\”,\\ n \\“ 1002021000029411 D \\”:\\“ 1002021000029411 \\”, \\ n \\“ 1005071000029666 D \\”:\\“ 1005071000029666 \\”,\\ n \\“ 1005071000033139 D \\”:\\“ 1005071000033139 \\”,\\ n \\“ 1005071000037533 D \\”:\\“ 1005071000037533 \\”,\\ n \\“ 1005071000038605 D \\“:\\” 1005071000038605 \\“,\\ n \\” 1005071000045298 D \\“:\\” 1005071000045298 \\“,\\ n \\” 1005071000045517 D \\“:\\” 1005071000045517 \\“,\\ n \\” 1005071000046989 D \\“:\\ “” 1005071000046989 \\“,\\ n \\” 1005071000056183 D \\“:\\” 1005071000056183 \\“,\\ n \\” 1005491000019560 D \\“:\\” 1005491000019560 \\“,\\ n \\” 2000071000163308 S \\“:\\” 2000071000163308 \\“, \\ n \\“ 2000071000163361 S \\”:\\“ 2000071000163361 \\” \\ n}}
我的工作灯适配器
function buildFromAccounts(userId) {
path = "xxxxxxxxxxxxxxxxx";
var input = {
method : 'post',
returnedContentType : 'plain',
path : path,
body:{
contentType:'application/json; charset=UTF-8',
content:
JSON.stringify({
"userId": userId.toString()
})
}
};
return WL.Server.invokeHttp(input);
}
问题是,如何在Worklight中将这种纯格式转换为json格式?
您为returnedContentType
设置了什么? JSON还是纯文本?
编辑:由于您返回平原...
尝试类似以下操作: var obj = JSON.parse(response.text)
看起来您的后端返回json。 没有理由将其视为纯文本。 更改
returnedContentType : 'plain'
至
returnedContentType : 'json'
(可选-完全忽略此属性,WL服务器将尝试自动检测响应类型)
选项#2-您可以随时使用
var jsonObj = JSON.parse(jsonString);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.