Using javascript get JSON data (from Tumblr) -
i'm trying read tumblr posts via json api.
using api, data passed this:
var tumblr_api_read= { "posts":[ "id":"1234", "regular-title":"this title of post", "regular-body":"this body of post" ] }
i'm having trouble returning "regular-title" , "regular-body".
my js code looks this:
var tumblr= tumblr_api_read['posts']; (eachpost in tumblr) { var id=posts[eachpost].id; //works fine var regulartitle=posts[eachpost].regular-title; //returns nan }
i assuming because posts[eachpost].regular-title has dash in not able find documentation on how make work in situation!
thanks.
javascript variable names can't contain special characters -
in example. if have property special characters in name way access []
method you've used access posts
object above gives option pass property name string.
var regulartitle = posts[eachpost]['regular-title'];
Comments
Post a Comment