ruby - How do I format this json correctly? -


having problem translating json code form dataobject...

  var dataobject = {       "timeline":       {           "headline":"the main timeline headline goes here",           "type":"default",           "text":"<p>intro body text goes here, html ok</p>",           "asset": {               "media":"http://yourdomain_or_socialmedialink_goes_here.jpg",               "credit":"credit name goes here",               "caption":"caption text goes here"           },           "date": [               {                   "startdate":"2011,12,10",                   "enddate":"2011,12,11",                   "headline":"headline goes here",                   "text":"<p>body text goes here, html ok</p>",                   "asset": {                       "media":"http://twitter.com/arjunasoriano/status/164181156147900416",                       "thumbnail":"optional-32x32px.jpg",                       "credit":"credit name goes here",                       "caption":"caption text goes here"                   }               }           ],           "era": [               {                   "startdate":"2011,12,10",                   "enddate":"2011,12,11",                   "headline":"headline goes here",                   "text":"<p>body text goes here, html ok</p>",               }           ]       }   } 

into method...

def timeline        t = {}   t['timeline'] = {}   t['timeline']['headline'] = "lorem"   t['timeline']['text'] = "default"   t['timeline']['asset'] = {}   t['timeline']['asset']['media'] = ""   t['timeline']['asset']['credit'] = ""   t['timeline']['asset']['caption'] = ""    t['timeline']['date'] = [{}]   t['timeline']['date']['startdate'] = "2011,12,10"   t['timeline']['date']['enddate'] = "2011,12,11"   t['timeline']['date']['headline'] = ""   t['timeline']['date']['text'] = ""   t['timeline']['date']['asset'] = {}   t['timeline']['date']['asset']['media'] = ""   t['timeline']['date']['asset']['thumbnail'] = ""   t['timeline']['date']['asset']['credit'] = ""   t['timeline']['date']['asset']['caption'] = ""    t['timeline']['era'] = [{}]   t['timeline']['era']['startdate'] = "2011,12,10"   t['timeline']['era']['enddate'] = "2011,12,11"   t['timeline']['era']['headline'] = ""   t['timeline']['era']['text'] = ""    return t end 

specifically i'm uncertain

t['timeline']['date'] = [{}] 

and

t['timeline']['era'] = [{}] 

how should write lines?

t['timeline']['date'] = [{}] 

that should work fine. have add attributes different. this:

t['timeline']['date'][0]['startdate'] = "2011,12,10"                      ^^^                      first element in array 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -