0

Below is my JSON string which am sending from my iOS native code to java script, by calling evaluateJavaScript on WKWebView. But when I run the project I am getting an error stated below(am using WKWebview to show my html file).

JSON:

{
"config": {
    "APIUrl": "https:some Url",
    "provider": "ActiveDirectory",
    "UserDetails": {
        "UserName": "Test User",
        "FullName": "",
        "EMailAddress": ""
    },
    "formdata": [{
        "postData": "{\"args\":[{\"Name\":\"ProcessName\",\"Value\":\"offlineformios\"},{\"Name\":\"isSubmitForm\",\"Value\":true}}]}",
        "url": "https:Get Url",
        "type": "POST",
        "responseStatus": 200
    },{
        "postData": "{\"args\":[{\"Name\":\"ProcessName\",\"Value\":\"offlineformios\"},{\"Name\":\"isSubmitForm\",\"Value\":true}}]}",
        "url": "https:Get Url",
        "type": "POST",
        "responseStatus": 200
    }],
    "CDNURL": "file: Local file path",
    "queryString": {
        "PROCESS": "offlineformios"
    },
    "auth": "Basic test auth",
    "culture": "en-US"
  }
}

Error:

WKJavaScriptExceptionMessage=SyntaxError: JSON Parse error: Expected '}', WKJavaScriptExceptionColumnNumber=32,

I have tried with jsonlint.com to check whether my JSON string is valid or not but it showing as valid. So I could not find any solutions,if anyone can help me out this that would be greate and I would expect the solution for this!Thanks.

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Aneesh
  • 1
  • 2
  • _“which am sending from my iOS native code to java script”_ - and that means what exactly? How are you “sending” it, and who receives it where and how? – CBroe Feb 01 '18 at 09:53
  • am using WKWebView(evaluateJavaScript). – Aneesh Feb 01 '18 at 10:00

2 Answers2

0

It may be an Issue with the escape char of PostData

"postData": "{\"args\":[{\"Name\":\"ProcessName\",\"Value\":\"offlineformios\"},{\"Name\":\"isSubmitForm\",\"Value\":true}}]}",
0

Unexpected token at 235 which is

{\"args\":[{\"Name\":\"ProcessName\",\"Value\":\"offlineformios\"},{\"Name\":\"isSubmitForm\",\"Value\":true}}]}

So it may help to be run through the stringify and back:

var JSObject = {
"config": {
    "APIUrl": "https:some Url",
    "provider": "ActiveDirectory",
    "UserDetails": {
        "UserName": "Test User",
        "FullName": "",
        "EMailAddress": ""
    },
    "formdata": [{
        "postData": "{\"args\":[{\"Name\":\"ProcessName\",\"Value\":\"offlineformios\"},{\"Name\":\"isSubmitForm\",\"Value\":true}}]}",
        "url": "https:Get Url",
        "type": "POST",
        "responseStatus": 200
    },{
        "postData": "{\"args\":[{\"Name\":\"ProcessName\",\"Value\":\"offlineformios\"},{\"Name\":\"isSubmitForm\",\"Value\":true}}]}",
        "url": "https:Get Url",
        "type": "POST",
        "responseStatus": 200
    }],
    "CDNURL": "file: Local file path",
    "queryString": {
        "PROCESS": "offlineformios"
    },
    "auth": "Basic test auth",
    "culture": "en-US"
  }
};
var JSString = JSON.stringify(JSObject)
var newObject = JSON.parse(JSString) 
console.log(newObject);
mplungjan
  • 169,008
  • 28
  • 173
  • 236