Page 1 of 1

Generic Service Unexpected Token

Posted: Fri Jun 14, 2013 2:30 pm
by Kapow36

For some reason my generic service is returning a unexpected token error.
The generic service is set up to receive parsed data from a REST service and then edit it for mapping. It works for all of the other times I use it.

So, the data I am receiving is (after parsed)...
code
{"Data":[{"THREADTITLE" : "Cool Test","CREATEDDATE" : "May, 20 2013 00:00:00","DESCRIPTION" : "<p>
This is a test forum post&#46;<&#47;p>","POSTDATE" : "May, 20 2013 17:18:19","LASTMODIFIED" : "May, 20 2013 00:00:00","POSTID" : "######","THREADID" : "######","FAMILY" : "Name","FIRSTNAME" : "Name","SPOUSEFIRST" : "Someone","EMAIL" : something@something&#46;com"},{"THREADTITLE" : "Cool Test","CREATEDDATE" : "May, 20 2013 00:00:00","DESCRIPTION" : "<p>
Ooo that's cool<&#47;p>","POSTDATE" : "June, 11 2013 10:16:17","LASTMODIFIED" : "June, 11 2013 00:00:00","POSTID" : "######","THREADID" : "######","FAMILY" : "Name","FIRSTNAME" : "Name","SPOUSEFIRST" : "Someone","EMAIL" : "Email"}]}
/code

also, here is the generic service implementation...

code
$t&#46;customImp = $t&#46;createClass(null, {
init: function(requestOptions) {
this&#46;__requestOptions = $&#46;extend({}, requestOptions);
},

Code: Select all

 process: function(settings) { 
     if (this&#46;__requestOptions&#46;echo) { 
      settings&#46;success(this&#46;__requestOptions&#46;echo); 
     } else { 
         var cdata = getData();&#47;&#47; load JSON data from javascript 
      settings&#46;success(cdata);&#47;&#47;send it to mapping 
         console&#46;log("done"); 
  } 
 settings&#46;complete('success'); 
 } 

});
/code
the getData() function returns the above JSON string.

I would normally be looking for a mistake for a lot longer than I did, but when I copy and past the response into the automatically create response feature in the generic service, it works smashingly.


Generic Service Unexpected Token

Posted: Fri Jun 14, 2013 3:53 pm
by Maryna Brodina

Hello! Your code looks correct, but data has an error:
There is a missing quote. Should be code"EMAIL" : "something@something&#46;com"/code instead of code"EMAIL" : something@something&#46;com"/code


Generic Service Unexpected Token

Posted: Fri Jun 14, 2013 6:47 pm
by Kapow36

Sorry, that was a copy and paste error, I had deleted the actual email address and put in a href="mailto:something@something.com" rel="nofollow"something@something.com/a. That's when the quote went missing. It is in the actual response.


Generic Service Unexpected Token

Posted: Fri Jun 14, 2013 6:53 pm
by Maryna Brodina

Everything looks correct. Could you give us you public app link so we can test your app and steps to reproduce the problem?


Generic Service Unexpected Token

Posted: Fri Jun 14, 2013 6:59 pm
by Kapow36

Absolutely, can I send that directly to the support email address then?


Generic Service Unexpected Token

Posted: Fri Jun 14, 2013 7:02 pm
by Maryna Brodina

Sure, email it to a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a


Generic Service Unexpected Token

Posted: Fri Jun 14, 2013 8:24 pm
by Maryna Brodina

There is a problem with json you save in data variable. In DESCRIPTION field there are newline and tabulation, that's why json parser doesn't work. You can fix for example setData function:
codefunction setData(value)&#47;&#47;sets data for most custom implementations
{
data = changeJSON(value);
data = data&#46;replace(&#47;[\n\r\t]&#47;g,'');
}/code
Should work after.


Generic Service Unexpected Token

Posted: Fri Jun 14, 2013 9:06 pm
by Kapow36

Excellent! Thanks Marina!