dicksonlaw583 / jsontoolkit

Companion scripts for json_encode() and json_decode() (GMS 2.x)
9 stars 2 forks source link

Problem with multiple data #3

Closed Harmanz closed 5 years ago

Harmanz commented 5 years ago

What i have:

"shift" {
"points": [ { "num": 1, "angle": { "min": -30.0, "max": 30.0 }, }, { "num": 3, "angle": { "min": -20.0, "max": 20.0 }, }, { "num": 7, "angle": { "min": -10.0, "max": 10.0 }, } ] }

What i have after usingjson_unset(WorkingJson,"shift","points",2);

"shift" {
"points": [ { "num": 1, "angle": { "min": -30.0, "max": 30.0 }, }, { "num": 3, "angle": { "min": -20.0, "max": 20.0 }, } }

What i have after

json_set(WorkingJson,"shift","points",2,"num",1);
json_set(WorkingJson,"shift","points",2,"angle","min",1);
json_set(WorkingJson,"shift","points",2,"angle","max",1);

or

json_insert(WorkingJson,"shift","points",2,"num",1);
json_insert(WorkingJson,"shift","points",2,"angle","min",1);
json_insert(WorkingJson,"shift","points",2,"angle","max",1);

"shift" {
"points": [ { "num": 1, "angle": { "min": -30.0, "max": 30.0 }, }, { "num": 3, "angle": { "min": -20.0, "max": 20.0 }, } }

What should be there

"shift" {
"points": [ { "num": 1, "angle": { "min": -30.0, "max": 30.0 }, }, { "num": 3, "angle": { "min": -20.0, "max": 20.0 }, }, { "num": 1, "angle": { "min": 1, "max": 1 }, } }

P.S. sorry if its not your problem again, but i need help :(

dicksonlaw583 commented 5 years ago

You should have used json_insert_nested() to append the submap to the list under "points", not json_set() or json_insert() with paths pointing to places that don't yet exist.

json_insert_nested(WorkingJson, "shift", "points", undefined, JsonStruct(JsonMap(
  "num", 1,
  "angle", JsonMap(
    "min", 1,
    "max", 1
  )
)));
Harmanz commented 5 years ago

Thank you very much. Only your extension allowed me to work with jsons comfortable.