javascript - Issue parsing JSON child elements -


here json string

    "book_types": {         "type": "1",         "books": [             {                 "name": "default",                 "cover": null,                 "lastupdated": {                     "microsecond": 114250,                     "ctime": "fri aug  9 01:27:45 2013"                 },                 "cat": 0,                 "other_thumbs": [],                 "book_type": 1,                 "thumbs": [],                 "id": "8001",                 "bk_follow_uids": [],                 "desc": "default",                 "bk_update_uids": [],                 "uid": 6001,                 "no": 1             }         ]     } } 

which valid. when call tojson(jsonstr), returns

object {book_types: object} book_types: object books: array[1]

here tojson function:

function tojson(jobj) {    obj = json && json.parse(jobj) || $.parsejson(jobj);    return(obj); } 

can please let me know why book_types nested in book_types.

i apoglize if trivial, not figure out reason.

thanks in advance

because book types is nested in object.

if take @ smaller example:

{     "book_types": {         "type": "1"      } } 

you have object containing member, member object called book_types , contains member string value "1".

just {} object. how json syntax works:

first hits object:

enter image description here

this return value, object see. inside object hits string book_types , value of it, object itself.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -