I want to turn this JSON file into arrays:
{"Elements":[{"LowerTolerance":1.4,"Name":"abc","ReferenceValue":1.5,"UpperTolerance":1.6,"Valid":false,"Value":1.8},{"LowerTolerance":20,"Name":"def","ReferenceValue":21.5,"UpperTolerance":23,"Valid":true,"Value":22.8},{"LowerTolerance":4.5,"Name":"ghi","ReferenceValue":5,"UpperTolerance":5.5,"Valid":false,"Value":4}],"Kamera":"c1"}
Here is a picture of the JSON file in a ordered tree form: JSON file
I want to get arrays like lowertolerance[], name[], referencevalue[] etc. so when I call an element of the array I get the value of it. For example: name[2] = ghi or referencevalue[0] = 1.5
I found this: https://stackoverflow.com/questions/6857468/converting-a-js-object-to-an-array#=
Now I have the problem that I don't know what to do when you have an object inside an object like I do.
I tried this:
var o = {"Elements": [{"LowerTolerance": 1.4, "Name": "abc", "ReferenceValue": 1.5, "UpperTolerance": 1.6}, {"LowerTolerance": 1.4, "Name": "abc", "ReferenceValue": 1.5, "UpperTolerance": 1.6}, {"LowerTolerance": 1.4, "Name": "abc", "ReferenceValue": 1.5, "UpperTolerance": 1.6}], "Kamera": "c1"};
var arr = $.map(o, function(el) { return el; })
document.getElementById("output").innerHTML = arr;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="output">
</div>
(jQuery is needed)
The ouput is: "[object Object],[object Object],[object Object],c1". What do I have to do to get the objects inside the main object?
You would make me really happy if you could help me!
Here is a simpler example of my problem:
var myObj = [{1:1, 2:2, 3:3}, {4:4, 5:5, 6:6}];
var array = $.map(myObj, function(value, index) {
return [value];
});
document.getElementById("output").innerHTML = array;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="output"></p>