Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Creating json object from DataObject


Reply

3 Posts   1929 Views

Avatar
zenmonkey

28 August 2010 at 3:40am Community Member, 528 Posts

I'm trying to create a json object from a DataObject for a $.getJson request in jQuery.

If I pass the url "api/v1/Page/18/Retailers.json" to the jQuery script it returns data but not with JSON request header. I've enabled api access on both the page type and the related dataobject Retailers.

Any Suggestion?

Avatar
swaiba

28 August 2010 at 4:17am Forum Moderator, 1796 Posts

How about...

$json = Convert::array2json($dataobject->getAllFields( ));

Avatar
zenmonkey

28 August 2010 at 5:42am Community Member, 528 Posts

Weird thing is when I use my code using the Java RESTClient suggested by the silverstripe book it returns a json object. However when I load it with jquery I can see the data in the response in Firebug but jquery doesn't parse it.