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   1962 Views

Avatar
zenmonkey

Community Member, 528 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?

Avatar
swaiba

Forum Moderator, 1799 Posts

28 August 2010 at 4:17am

How about...

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

Avatar
zenmonkey

Community Member, 528 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.