使用JSON中的数组存储具有不同值的多个参数 [英] Storing multiple parameters with different values using arrays in JSON
问题描述
我有3个班级,分别是A,B和C ......每个类具有不同的参数,即A - > a,b,c,d,e,f,B - >。 g,h,i,j和C - > K,L,M,N ...!每个参数有4个值,分别为min,max,def和cur ......!
I'm having 3 classes namely A, B and C...! Each class having different parameters, i.e, A-->a,b,c,d,e,f, B--> g,h,i,j and C--> k,l,m,n...! Each parameter having 4 values namely min,max,def and cur...!
`var obja="A": {
"a":{"Default":0.0,"Current":30.0,"Min":0.0,"Max":200.0},
"b":{"Default":0.0,"Current":60.0,"Min":0.0,"Max":10.44},
"c":{"Default":0.0,"Current":60.0,"Min":0.0,"Max":89.0},
"d":{"Default":1.0,"Current":60.0,"Min":1.0,"Max":255.0},
"e":{"Default":1.0,"Current":60.0,"Min":1.0,"Max":255.0},
"f":false
}
var objb="B":{
"g":{"Default":0.0,"Current":15.0,"Min":10.0,"Max":20.4},
"h":{"Default":1.0,"Current":120.0,"Min":1.0,"Max":255.0},
"i":{"Default":0.0,"Current":60.0,"Min":0.0,"Max":10.44},
"j":{"Default":1.0,"Current":60.0,"Min":1.0,"Max":255.0}
}
var objc="C":{
"k":{"Default":0.0,"Current":10.0,"Min":0.0,"Max":3.06},
"l":{"Default":1.0,"Current":3.5,"Min":0.0,"Max":2.55},
"m":{"Default":0.0,"Current":3.0,"Min":0.0,"Max":2.55},
"n":{"Default":0.0,"Current":401.0,"Min":0.0,"Max":1270.0}
}`
这是JSON中的正确方法,因为我是JSON的新手..!
我对此有任何建议表示感谢..!
我的尝试: < br $>
`var obja =A:{
a:{默认:0.0,当前:30.0, Min:0.0,Max:200.0},
b:{Default:0.0,Current:60.0,Min:0.0,Max:10.44},
c:{默认:0.0,当前:60.0,最小:0.0,最大:89.0},
d: {Default:1.0,Current:60.0,Min:1.0,Max:255.0},
e:{Default:1.0,Current:60.0 ,Min:1.0,Max:255.0},
f:false
}
var objb =B:{
g:{Default:0.0,Current:15.0,Min:10.0,Max:20.4},
h:{默认:1.0,当前:120.0,最小:1.0,最大:255.0},
我:{默认:0.0,当前:60.0,最小:0.0,最大:10.44},
j:{默认:1.0,当前:60.0, Min:1.0,Max:255.0}
}
var objc =C:{
k :{Default:0.0,Current:10.0,Min:0.0,Max:3.06},
l:{Default:1.0,Current: 3.5,Min:0.0,Max:2.55},
m:{Default:0.0,Current:3.0,Min:0.0,Max: 2.55},
n:{默认:0.0,当前:401.0,最小:0.0,最大:1270.0}
}`
Is it correct way in JSON as am new to JSON..!
I appreciate for any suggestion on this..!
What I have tried:
`var obja="A": {
"a":{"Default":0.0,"Current":30.0,"Min":0.0,"Max":200.0},
"b":{"Default":0.0,"Current":60.0,"Min":0.0,"Max":10.44},
"c":{"Default":0.0,"Current":60.0,"Min":0.0,"Max":89.0},
"d":{"Default":1.0,"Current":60.0,"Min":1.0,"Max":255.0},
"e":{"Default":1.0,"Current":60.0,"Min":1.0,"Max":255.0},
"f":false
}
var objb="B":{
"g":{"Default":0.0,"Current":15.0,"Min":10.0,"Max":20.4},
"h":{"Default":1.0,"Current":120.0,"Min":1.0,"Max":255.0},
"i":{"Default":0.0,"Current":60.0,"Min":0.0,"Max":10.44},
"j":{"Default":1.0,"Current":60.0,"Min":1.0,"Max":255.0}
}
var objc="C":{
"k":{"Default":0.0,"Current":10.0,"Min":0.0,"Max":3.06},
"l":{"Default":1.0,"Current":3.5,"Min":0.0,"Max":2.55},
"m":{"Default":0.0,"Current":3.0,"Min":0.0,"Max":2.55},
"n":{"Default":0.0,"Current":401.0,"Min":0.0,"Max":1270.0}
}`
推荐答案
它应该是这样的
it should be something like this
var obj = {
"A": {
"a": { "Default": 0.0, "Current": 30.0, "Min": 0.0, "Max": 200.0 },
"b": { "Default": 0.0, "Current": 60.0, "Min": 0.0, "Max": 10.44 },
"c": { "Default": 0.0, "Current": 60.0, "Min": 0.0, "Max": 89.0 },
"d": { "Default": 1.0, "Current": 60.0, "Min": 1.0, "Max": 255.0 },
"e": { "Default": 1.0, "Current": 60.0, "Min": 1.0, "Max": 255.0 },
"f": false
},
"B": {
"g": { "Default": 0.0, "Current": 15.0, "Min": 10.0, "Max": 20.4 },
"h": { "Default": 1.0, "Current": 120.0, "Min": 1.0, "Max": 255.0 },
"i": { "Default": 0.0, "Current": 60.0, "Min": 0.0, "Max": 10.44 },
"j": { "Default": 1.0, "Current": 60.0, "Min": 1.0, "Max": 255.0 }
},
"C": {
"k": { "Default": 0.0, "Current": 10.0, "Min": 0.0, "Max": 3.06 },
"l": { "Default": 1.0, "Current": 3.5, "Min": 0.0, "Max": 2.55 },
"m": { "Default": 0.0, "Current": 3.0, "Min": 0.0, "Max": 2.55 },
"n": { "Default": 0.0, "Current": 401.0, "Min": 0.0, "Max": 1270.0 }
}
}
// example
var aCur = obj.A.a.Current;
var bmin = obj.B.g.Min;
参考 JSON.parse() [ ^ ]解析JSON字符串的方法
视觉表示 Json Parser Online [ ^ ]
refer JSON.parse()[^] method for parsing the JSON string
for visual representation Json Parser Online[^]
这篇关于使用JSON中的数组存储具有不同值的多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!