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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

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

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

Creating json object from DataObject

Go to End

3 Posts   2562 Views


Community Member, 545 Posts

28 August 2010 at 3:40am

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?


Forum Moderator, 1899 Posts

28 August 2010 at 4:17am

How about...

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


Community Member, 545 Posts

28 August 2010 at 5:42am

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.