问题描述
我的json元数据是varjsondata=[{"QuestionId":1,"QuestionName":"Satisfaction","QuestionDescription":"Satisfaction","LanguageViewModel":[{"LanguageId":1,"languageCode":"bg","StatusName":"Updated"},{"LanguageId":2,"languageCode":"cs","StatusName":"Updated"},{"LanguageId":3,"languageCode":"da","StatusName":"Updated"},{"LanguageId":4,"languageCode":"de","StatusName":"Updated"},{"LanguageId":5,"languageCode":"el","StatusName":"Updated"},{"LanguageId":6,"languageCode":"en","StatusName":"Updated"},{"LanguageId":7,"languageCode":"es","StatusName":"Updated"},{"LanguageId":8,"languageCode":"et","StatusName":"Updated"},{"LanguageId":9,"languageCode":"fi","StatusName":"Updated"},{"LanguageId":10,"languageCode":"fr","StatusName":"Updated"},{"LanguageId":11,"languageCode":"he","StatusName":"Updated"},{"LanguageId":12,"languageCode":"hi","StatusName":"Updated"},{"LanguageId":13,"languageCode":"hr","StatusName":"Updated"},{"LanguageId":14,"languageCode":"hu","StatusName":"Updated"},{"LanguageId":15,"languageCode":"it","StatusName":"Updated"},{"LanguageId":16,"languageCode":"ja","StatusName":"Updated"},{"LanguageId":17,"languageCode":"ko","StatusName":"Updated"},{"LanguageId":18,"languageCode":"lt","StatusName":"Updated"},{"LanguageId":19,"languageCode":"lv","StatusName":"Updated"},{"LanguageId":20,"languageCode":"ms","StatusName":"Updated"},{"LanguageId":21,"languageCode":"nl","StatusName":"Updated"},{"LanguageId":22,"languageCode":"no","StatusName":"Updated"},{"LanguageId":23,"languageCode":"pl","StatusName":"Updated"},{"LanguageId":24,"languageCode":"pt","StatusName":"Updated"},{"LanguageId":25,"languageCode":"pt-br","StatusName":"Updated"},{"LanguageId":26,"languageCode":"ro","StatusName":"Updated"},{"LanguageId":27,"languageCode":"ru","StatusName":"Updated"},{"LanguageId":28,"languageCode":"sk","StatusName":"Updated"},{"LanguageId":29,"languageCode":"sl","StatusName":"Updated"},{"LanguageId":30,"languageCode":"sv","StatusName":"Updated"},{"LanguageId":31,"languageCode":"th","StatusName":"Updated"},{"LanguageId":32,"languageCode":"tr","StatusName":"Updated"},{"LanguageId":33,"languageCode":"zh-sim","StatusName":"Updated"},{"LanguageId":34,"languageCode":"zh-tra","StatusName":"Updated"},{"LanguageId":35,"languageCode":"ar-me","StatusName":"Updated"},{"LanguageId":36,"languageCode":"zh-hk","StatusName":"Updated"},{"LanguageId":37,"languageCode":"fr-ca","StatusName":"ToBeLocalized"}]}];
我要的结果是将分别添加到数组中<scripttype="text/javascript">$(function(){varjsondata=[{"QuestionId":1,"QuestionName":"Satisfaction","QuestionDescription":"Satisfaction","LanguageViewModel":[{"LanguageId":1,"languageCode":"bg","StatusName":"Updated"},{"LanguageId":2,"languageCode":"cs","StatusName":"Updated"},{"LanguageId":3,"languageCode":"da","StatusName":"Updated"},{"LanguageId":4,"languageCode":"de","StatusName":"Updated"},{"LanguageId":5,"languageCode":"el","StatusName":"Updated"},{"LanguageId":6,"languageCode":"en","StatusName":"Updated"},{"LanguageId":7,"languageCode":"es","StatusName":"Updated"},{"LanguageId":8,"languageCode":"et","StatusName":"Updated"},{"LanguageId":9,"languageCode":"fi","StatusName":"Updated"},{"LanguageId":10,"languageCode":"fr","StatusName":"Updated"},{"LanguageId":11,"languageCode":"he","StatusName":"Updated"},{"LanguageId":12,"languageCode":"hi","StatusName":"Updated"},{"LanguageId":13,"languageCode":"hr","StatusName":"Updated"},{"LanguageId":14,"languageCode":"hu","StatusName":"Updated"},{"LanguageId":15,"languageCode":"it","StatusName":"Updated"},{"LanguageId":16,"languageCode":"ja","StatusName":"Updated"},{"LanguageId":17,"languageCode":"ko","StatusName":"Updated"},{"LanguageId":18,"languageCode":"lt","StatusName":"Updated"},{"LanguageId":19,"languageCode":"lv","StatusName":"Updated"},{"LanguageId":20,"languageCode":"ms","StatusName":"Updated"},{"LanguageId":21,"languageCode":"nl","StatusName":"Updated"},{"LanguageId":22,"languageCode":"no","StatusName":"Updated"},{"LanguageId":23,"languageCode":"pl","StatusName":"Updated"},{"LanguageId":24,"languageCode":"pt","StatusName":"Updated"},{"LanguageId":25,"languageCode":"pt-br","StatusName":"Updated"},{"LanguageId":26,"languageCode":"ro","StatusName":"Updated"},{"LanguageId":27,"languageCode":"ru","StatusName":"Updated"},{"LanguageId":28,"languageCode":"sk","StatusName":"Updated"},{"LanguageId":29,"languageCode":"sl","StatusName":"Updated"},{"LanguageId":30,"languageCode":"sv","StatusName":"Updated"},{"LanguageId":31,"languageCode":"th","StatusName":"Updated"},{"LanguageId":32,"languageCode":"tr","StatusName":"Updated"},{"LanguageId":33,"languageCode":"zh-sim","StatusName":"Updated"},{"LanguageId":34,"languageCode":"zh-tra","StatusName":"Updated"},{"LanguageId":35,"languageCode":"ar-me","StatusName":"Updated"},{"LanguageId":36,"languageCode":"zh-hk","StatusName":"Updated"},{"LanguageId":37,"languageCode":"fr-ca","StatusName":"ToBeLocalized"}]}];vardataQuestion=[];$(eval(jsondata)).each(function(){//格式为,\QuestionId,QuestionName,QuestionDescription,LanguageViewModel为其key//例如QuestionId的Key对应的值就是1,QuestionName的key对应的值就是Satisfaction});
解决方案
解决方案二:
eval之后不就是数组了么?
解决方案三:
楼主的意思是想只取到key还是?
解决方案四:
没看懂
解决方案五:
用这个JavaScriptSerializer
解决方案六:
vartest=[];$(eval(jsondata)).each(function(item){test.push(item.的QuestionId);});
解决方案七:
varas=$.parseJSON(jsondata);将的到的json数据反序列化过来for(i=0;i<a.length;i++){vara=as[i];a.id;//取得对应id}