homepage Welcome to WebmasterWorld Guest from 54.196.197.153
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
JSON accessing object with numeric index
camilord




msg:4521337
 12:35 am on Nov 22, 2012 (gmt 0)


var jsn = {"3":{"334":[{"skin_condition_question_answer_id":"957","case_details_answer_value":"fdfsdfsdf"}],"335":[{"skin_condition_question_answer_id":"1276","case_details_answer_value":"Right Upper Arm"}],"336":[{"skin_condition_question_answer_id":"966"}],"337":[{"skin_condition_question_answer_id":"968"}],"338":[{"skin_condition_question_answer_id":"970","case_details_answer_value":"fdsfsddfsfds"}],"374":[{"skin_condition_question_answer_id":"1079"}],"375":[{"skin_condition_question_answer_id":"1084"}],"376":[{"skin_condition_question_answer_id":"1090"}],"377":false}};

var jq = {"3":{"374":{"0":{"skin_condition_question_answer_id":"1076"}},"375":{"0":{"skin_condition_question_answer_id":"1082"}},"376":{"0":{"skin_condition_question_answer_id":"1090"}},"377":""}};


anyone can help me please... javascript guru out there.. please help..

how do i access the object?

is it?

alert(jsn[0]); // undefined
alert(jq[0]); // undefined

alert(jsn.3); // error
alert(jq.3); // error

anyone?

 

camilord




msg:4521342
 12:46 am on Nov 22, 2012 (gmt 0)

oooopppsss.. nevermind.. i got the answer... heheheh..


var jsn = {"3":{"334":[{"skin_condition_question_answer_id":"957","case_details_answer_value":"fdfsdfsdf"}],"335":[{"skin_condition_question_answer_id":"1276","case_details_answer_value":"Right Upper Arm"}],"336":[{"skin_condition_question_answer_id":"966"}],"337":[{"skin_condition_question_answer_id":"968"}],"338":[{"skin_condition_question_answer_id":"970","case_details_answer_value":"fdsfsddfsfds"}],"374":[{"skin_condition_question_answer_id":"1079"}],"375":[{"skin_condition_question_answer_id":"1084"}],"376":[{"skin_condition_question_answer_id":"1090"}],"377":false}};

var jq = {"3":{"374":{"0":{"skin_condition_question_answer_id":"1076"}},"375":{"0":{"skin_condition_question_answer_id":"1082"}},"376":{"0":{"skin_condition_question_answer_id":"1090"}},"377":""}};

function testJS() {
alert("PHP json_encode() -> " + jsn["3"]["334"]["0"]["skin_condition_question_answer_id"]);
alert("jQuery Object/Array ->" + jq["3"]["374"]["0"]["skin_condition_question_answer_id"]);
}

daveVk




msg:4521429
 6:19 am on Nov 22, 2012 (gmt 0)

Dot notation should also work

jsn.3.334.0.skin_condition_question_answer_id

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved