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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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

Avatar
zenmonkey

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?

Avatar
swaiba

Forum Moderator, 1899 Posts

28 August 2010 at 4:17am

How about...

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

Avatar
zenmonkey

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.