我有一个Rails控制器,它将一些模型呈现给json.
@events = Event.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @events }
format.json { render :json => { :results => @events } }
end
Run Code Online (Sandbox Code Playgroud)
输出如下所示:
{
"results":
[
{
"name":"test",
"created_at":"2011-03-23T13:32:57Z",
"latitude":60.0,
"location":null,
"updated_at":"2011-04-14T16:38:54Z",
"id":1,
"longitude":30.0,
"takes_place_at":"2011-03-23T13:32:00Z"
},
{
"name":"x",
"created_at":"2011-03-23T13:36:44Z",
"latitude":60.0,
"location":null,
"updated_at":"2011-03-23T13:36:44Z",
"id":2,
"longitude":30.0,
"takes_place_at":"2011-03-23T13:36:00Z"
},
{
"name":"Gruempi",
"created_at":"2011-03-24T14:00:32Z",
"latitude":60.0,
"location":null,
"updated_at":"2011-04-14T16:39:47Z",
"id":3,
"longitude":30.0,
"takes_place_at":"2011-03-24T14:00:00Z"
},
{
"name":"ba",
"created_at":"2011-04-10T22:40:07Z",
"latitude":60.0,
"location":"12,
14",
"updated_at":"2011-04-10T22:40:07Z",
"id":4,
"longitude":30.0,
"takes_place_at":"2011-04-10T22:36:00Z"
},
{
"name":"sfasdfs",
"created_at":"2011-04-10T22:44:55Z",
"latitude":60.0,
"location":"we're try …Run Code Online (Sandbox Code Playgroud)