Renjith V
Posts: 0
Joined: Mon Dec 31, 2012 4:54 am

Manipulate REST output before JSON parsing

Am stuck with a problem. In one of the REST calls, the server seems to be returning "None" if there is not data to be returned. I agree that the data being returned in not JSON formatted and the correction has to be in the server. But is there a way that I can handle this in the app, to change "None" to empty before the JSON parsing is done?

Renjith V
Posts: 0
Joined: Mon Dec 31, 2012 4:54 am

Manipulate REST output before JSON parsing

Anyone out there please :(

Emmz
Posts: 0
Joined: Sat Jun 23, 2012 11:06 pm

Manipulate REST output before JSON parsing

I use this...
For The Rest Service COMPLETE event add..
code
var responseTxt =(jqXHR.responseText);
var responseTxt = JSON.parse(responseTxt);
console.log(responseTxt.response);//see the object
if (ParsedResponse == 'None'){
//do this
}
/code

As I need to check for returned data of servers output b4 Acting..

Renjith V
Posts: 0
Joined: Mon Dec 31, 2012 4:54 am

Manipulate REST output before JSON parsing

Hey Neil, thank you, it's a relief to know that it can be done. But I am still a bit lost. My aim is to set back a valid JSON into the actual data so that when the default parsing happens it's gets a valid one.
Could you please help me out on how to handle that?

In my case the parse function throws an error. See the stack below:

Uncaught SyntaxError: Unexpected token N jquery-1.8.2.js:514
jQuery.extend.parseJSON jquery-1.8.2.js:514
Tiggzi.DataSource.$t.createClass.__responseDataHandler tiggzi.js:1207
proxy jquery-1.8.2.js:775
fire jquery-1.8.2.js:974
self.fireWith jquery-1.8.2.js:1082
done jquery-1.8.2.js:7788
callback

Renjith V
Posts: 0
Joined: Mon Dec 31, 2012 4:54 am

Manipulate REST output before JSON parsing

I just tried to add a console.log to know whether those functions (Succes/Error/Complete) are being called. I guess, none of them are even called. Nothing came out on the console expect for the above mentioned exception :(

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Manipulate REST output before JSON parsing

Just start with this and go from there:

code
var responseTxt =(jqXHR.responseText);
console.log(responseTxt);
/code

Renjith V
Posts: 0
Joined: Mon Dec 31, 2012 4:54 am

Manipulate REST output before JSON parsing

I did exactly the same. But the callback functions (none of them are being called).
And nothing comes in console, just the exception that I pasted above.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Manipulate REST output before JSON parsing

Add 'error' callback to see what's happening.

Renjith V
Posts: 0
Joined: Mon Dec 31, 2012 4:54 am

Manipulate REST output before JSON parsing

Adding it as a Reply to add an image.

Renjith V
Posts: 0
Joined: Mon Dec 31, 2012 4:54 am

Manipulate REST output before JSON parsing

No, 'error' call back also is not called.

I also tried this. Instead of using the Invoke service method, I tried to use 'Run Javascript' and tried to invoke the service like serviceInstanceName.execute({}); within a try/catch block, hoping that I can catch this error.
Why is that? Because the error output clearly says an uncaught exception :(
Image

Return to “Issues”