Looking for an example where my web server builds a hierarchical business object and returns this business object to the client using Json.
I have successfully returned json using a foxpro cursor by using:
return "cursor:myCursor"
I recommend you take a look at this White Paper I just published. The second half of the paper deals with creating Web Connection REST APIs.
Building and Consuming REST API Services with FoxPro
The first part of the paper is also good if you're new to REST in general and some of the basic HTTP concepts as it introduces interacting with REST APIs from the client side, but the second part is specifically to Web Connection and REST services.
The short answer to your question is: You can return FoxPro objects. For a Business object you'd want to return either a cursor result (for a query method) or an object (the .oData
member) or a you might want to build up an object and compose an object using CREATEOBJECT("EMPTY")
plus ADDPROPERTY()
to create complex nested objects and collections. You can also return cursors as child collections in the JSON. The white paper has examples of all of these.
+++ Rick ---
I can create the Json with the nested child properties. What I do not understand is how should the web server return the Json to the client?
If you're using a REST Service - which it looks like you're using - you just return the object from your method.
Read the white paper - it'll explain.
+++ Rick --