HTTP Adapter Error "Runtime: Failed to parse JSON string"
ibm-mobilefirst
Solution
You can change returnedContentType to "plain", this will make WL server return content as a big string and not attempt to parse it. Then in your adapter you can use var obj = JSON.parse(response.text)
Problem
I am using IBM Worklight Studio, and trying to create HTTP Adapter which retrieve JSON object from external http server. When I just access target http server with HTTP Get access(with browser, for example), I know their response is like following array style JSON format: ``` [ { "xxx":"aaa", "yyy":"bbb", ... }, { "xxx":"ccc", "yyy":"ddd", ... }, : { "xxx":"eee", "yyy":"fff", ... } ] ``` And I had created HTTP Adapter which would retrieve above information ``` var input = { method : 'get', returnedContentType : 'json', path : path }; return WL.Server.invokeHttp(input); ``` Now I tried to invoke this adapter with "Run As -> Invoke Worklight Procedure", then I got this error message: ``` { "errors": [ "Runtime: Failed to parse JSON string\n\n[\n {\n (raw JSON data) } ], "info": [], "isSuccessful": false, "warnings": [] } ``` And in my log console, worklight says following error messages: ``` FWLSE0101E: Caused by: java.io.IOException: Expecting '{' on line 2, column 2 instead, obtained token: 'Token: [' ``` From above information, it seems that worklight would expect that returned JSON object need to start with "{", not "[". Is this my guess right? Are there any workaround for this? Thanks for advance.