Arcadier / Developer-Community-Support

:revolving_hearts: Share new ideas with us and report bugs/problems here
4 stars 1 forks source link

problem with JSON data structure after response #7

Closed ABHINAV112 closed 3 years ago

ABHINAV112 commented 5 years ago

Your issue/question: After assigning JSON objects to a JSON the same change is made to every inner JSON instead of only the required JSON which should be changed.

What you expect to achieve Each assignment should only be made to the required JSON object and not every inner JSON object.

What happens instead Every inner JSON object is updated at the same time when only one of them should get updated.

Screenshots Screenshot from 2019-06-10 10-49-48 Screenshot from 2019-06-10 10-50-05

Your system/software details Running an Ubuntu 18.04 LTS

naseer2426 commented 5 years ago

Try initializing the "TimeData" inside the for loop.

Since you assigned "TimeData" outside the for loop in line 23, when you are assigning megaTimeData[i] to TimeData in line 27, it essentially references megaTimeData[i] to the same memory location as "TimeData". That is the reason your changes are reflected everywhere in your JSON file

ABHINAV112 commented 5 years ago

I did that but now i changed up the structure of the inner JSON object, and now it's not working. I am now getting an error which says assigning a property to an undefined object.

Screenshot from 2019-06-10 11-23-55 Screenshot from 2019-06-10 11-24-08

naseer2426 commented 5 years ago

You have used i in both the inner and outer for loops. I think that is what is causing the problem. Try changing inner for loop variable to j.

ABHINAV112 commented 5 years ago

Oh ok made the changes and adjusted some code it's working now.

Thanks