Jump to:

23493 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Creating json object from DataObject

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

Page: 1
Go to End
Author Topic: 1910 Views
  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Creating json object from DataObject Link to this post

    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?

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Creating json object from DataObject Link to this post

    How about...

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

  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Re: Creating json object from DataObject Link to this post

    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.

    1910 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.