Jonathan Clarke
Posts: 0
Joined: Wed Oct 17, 2012 10:24 pm

Complex JSON Posts from Service

Dear All,

I'm trying to post a simple example of a more complex(!) JSON structure, that I want to extend, once I've shown this working. My receiving service expects the MyObject portion to be there, but I can't see how I can do this embedding of the object attributes using the post service.

{"MyObject":{"id":"1","name":"MyName"}}

Does anyone know how to do this without writing some Javascript? I can certainly parse complex structures as part of a response, but what about the request body?

Jonathan.

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

Complex JSON Posts from Service

Today it would need to be done in JavaScript. Create a structure that looks like this in JavaScript: {"MyObject":{"id":"1","name":"MyName"}} and return it in mapping, for example.

Something like this:
code
return {"MyObject":{"id":"1","name":"MyName"}};
/code

We will be adding this option to the service editor. When you define request parameters you will be able to define complex objects.

Jonathan Clarke
Posts: 0
Joined: Wed Oct 17, 2012 10:24 pm

Complex JSON Posts from Service

Hi Max,

Thanks for this. I tried your solution, but I still have some problems. I have created a service that posts a structure like the one above, only that I'm mapping {"id":"1","name":"MyName"} to a parameter of MyObject. This Post service works in the test screen, but when I try and invoke it from a button, nothing happens, and there are no errors, nor does Firebug show an error. I have tested that the service invocation works, in itself, by changing it to a GET, and it works immediately. I have also trying to send a JSON POST using a $.ajax call in Javascript, but I cannot get the encoding of the Post changed from application/x-www-form-urlencoded to application/json, even though I am specifying it as the content-type. Are these problems that have been reported, at all? Given the data structure above, how do you recommend sending a javascript post?

Jonathan.

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

Complex JSON Posts from Service

When you use $.ajax -- you don't use any Tiggzi features, so I can't tell you why it doesn't work.

Can you share the service URL and the request parameters to invoke the service (including the correct JSON object)? If you would rather not share it here, you can send it to support@tiggzi.com.

Jonathan Clarke
Posts: 0
Joined: Wed Oct 17, 2012 10:24 pm

Complex JSON Posts from Service

Hi Max,

Sorry, I can't release any of the URL information, because it's a client's domain. However, would this problem be because the post, even through the service, is surfacing as a javascript posting, and therefore trying to cross domains, which is forbidden? I'd like to achieve the same level of REST post functionality as you would get with a normal Android (for example) HttpHost Post call.

Jonathan

Jonathan Clarke
Posts: 0
Joined: Wed Oct 17, 2012 10:24 pm

Complex JSON Posts from Service

I seem to having the same problem as this entry:

https://getsatisfaction.com/tiggzi/to...

The test screen works with a REST post, but not during service invocation under a button.

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

Complex JSON Posts from Service

They look similar but really different. The problem here I think is that the JSON sent is converted to a string and the service complains. Looks like a problem on our end.

Jonathan Clarke
Posts: 0
Joined: Wed Oct 17, 2012 10:24 pm

Complex JSON Posts from Service

Just a general question, then. Given the automatic export process that Tiggzi has got, why aren't things like API handlers built into the back of the source, rather than in the HTML? For example, using Java Jet Templating, you'd be able to build in a bunch of Java classes that would do the HTTPHost work in the background, and then you'd need only to connect them with Tiggzi linkage. The HTML5 front-end is great, but the power of a downloadable app has to be in the backend of the app, otherwise you'd just build a web app designed just for the mobile market.

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

Complex JSON Posts from Service

I hope I understand the question correctly, but when you export the app you get HTML/JS/CSS and optionally PhoneGap. It all runs in the browser -- so there is no Java. We do provide app backend in the form of a cloud database and Push Notifications. We will be offering server-side code in the near future.

Return to “Issues”