本文介绍了如何以json格式转换javascript数组的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在该类中有一个类AgeCriteria我还有2个类,如MinmumAge和MaximumAge。
如何使用Jquery获得低于Json格式。
I have a class AgeCriteria in that class i have 2 more classes like MinmumAge and MaximumAge.
how can i get below Json Format using Jquery.
"AgeCriteria": {
"MinimumAge": {
"Age": "50",
"AgeUnitID": "2",
"AgeUnit": "Year"
},
"MaximumAgemumAge": {
"Age": "",
"AgeUnitID": "",
"AgeUnit": ""
}
}
我尝试过:
What I have tried:
var _AgeCriteria=[];
var MinAgeCriteria = { AgeType: "Min", Age: minAge, AgeUnitID: "1", AgeUnit: minUnit };
_AgeCriteria.push(MinAgeCriteria);
var MaxAgeCriteria = { AgeType: "Max", Age: maxAge, AgeUnitID: "1", AgeUnit: maxUnit };
_AgeCriteria.push(MaxAgeCriteria);
以上数组给出这个结果
above array give this result
[{"AgeType":"Min","Age":"15","AgeUnitID":"1","AgeUnit":"Year"},{"AgeType":"Max","Age":"25","AgeUnitID":"1","AgeUnit":"Year"}]
推荐答案
var criteria = {AgeCriteria: {MinimumAge : {Age:50, AgeUnitID:2, AgeUnit:"Year"}, MaximumAgemumAge: {Age:25, AgeUnitID:1, AgeUnit:"Year"}}};
这篇关于如何以json格式转换javascript数组的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!