[英]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.