jquery - Determine if single value or sub array JSON -
i have algorithm binds object mvc (c#) view. key , data can anything, implementer.
the issue having cannot determine if in json string array or simple string. following code works recursively. if array, needs dig deeper. otherwise, bind value found based on key , value.
function constructview(data) { for(var key in data) { if (data[key].length > 1) { var count = 0; while (count < data.length) { constructview(data[count]); count++; } } $("#" + key).html(data[key]); } } this prototype, @ moment not generate components bindings.
ok, so, issue:
when pass in
{"data":"this response","strings":["test1","test2"]} it returns 18 , 2 lengths. because both technically arrays valid length.
is there way item length? considers lone string 1 item , array respective item count?
i can verify json array passed in properly.
any appreciated!
array.isarray(x) will check array, although you'll need polyfill (pretty easy find) if need support legacy browsers.
typeof x === "string" will indicate string
Comments
Post a Comment