Click here to Skip to main content
15,904,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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}
}`


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}
}`
Posted
Updated 26-Sep-16 20:34pm

1 solution

it should be something like this

JavaScript
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;


refer JSON.parse()[^] method for parsing the JSON string

for visual representation Json Parser Online[^]
 
Share this answer
 
v2
Comments
Karthik_Mahalingam 27-Sep-16 4:33am    
pls provide the same output.
or if you have some screenshot
Member 11373970 27-Sep-16 5:01am    
It should be like this in grid format as 1st and 2nd row.(Unable to attach screenshot here)
5 2 4 200 50 10 1 600 5 51 50 1

8 4 2 620 10 55 2 150 8 16 25 0

Displays only current value of each parameter..!
Provided by you is for one row..!
Karthik_Mahalingam 27-Sep-16 5:04am    
how did you format this data
https://snag.gy/ for screenshot
Member 11373970 27-Sep-16 5:33am    
Thanks Karthik for your response..!
https://snag.gy/8MGxLn.jpg (For Screenshot)

Displays only current values of each parameter and it was not required to mention Min, Max and default vales.
Instead it should be only with current values like below.

var obj = {
"A": {
"a": { "Current": 30.0},
"b": { "Current": 60.0},
"c": { "Current": 60.0},
"d": { "Current": 60.0},
"e": { "Current": 60.0},
"f": false
},
"B": {
"g": { "Current": 30.0},
"h": { "Current": 60.0},
"i": { "Current": 60.0},
"j": { "Current": 60.0},
},
"C": {
"k": { "Current": 30.0},
"l": { "Current": 60.0},
"m": { "Current": 60.0},
"n": { "Current": 60.0},
}
}

Please suggest me the best way..!
Karthik_Mahalingam 27-Sep-16 5:39am    
what is the logic to display the data in the screenshot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900