Jump to content

JsonUtil issue


jollypolly17

Recommended Posts

Posted

Hello, I'm trying to read a json file in a papyrus script, then modify some values and finally save them back to the json file. However whenever i do it, it deletes all the previous data that was stored in the json file and only writes the values that were modified in the papyrus script. Here's a simple example of whats happening :

 

The json file (test.json) would initially look like this:

{

"key1" : [0.0, 1.0, 2.0]

"key2" : [3.0, 4.0, 5.0]

"key3" : [6.0, 7.0, 8.0]

}

 

The Papyrus script like this:

 

String FileName ="../test.json"

JsonUtil.Load(FileName)

JsonUtil.SetPathFloatValue(FileName , "key2[1]", 20.0)

JsonUtil.Save(FileName)

 

The resulting json file is this:

{

"key2" : [none, 20.0]

}

instead  of what i'm trying to get which is this:

{

"key1" : [0.0, 1.0, 2.0]

"key2" : [3.0, 20.0, 5.0]

"key3" : [6.0, 7.0, 8.0]

}

 

My question is how do I modify existing values in the json file without wiping out all of the previous data? Thanks

 

 

Posted

Have you tried this:

String FileName = "../test.json"

JsonUtil.Load(FileName)
JsonUtil.FloatListSet(FileName, "key2", 1, 20.0)
JsonUtil.Unload(FileName)

or this:

String FileName = "../test.json"

JsonUtil.Load(FileName)
float[] key2 = JsonUtil.FloatListToArray(FileName, "key2")
key2[1] = 20.0
JsonUtil.FloatListCopy(FileName, "key2", key2)
JsonUtil.Unload(FileName)

 

Posted
2 hours ago, jollypolly17 said:

Thanks for your reply Hawk. Was actually just a stupid mistake : I had forgotten the commas in the json file... Works fine now.

 

For future reference, you should always add a sanity check for things like that.

String FileName = "../test.json"

if !JsonUtil.Load(FileName)
    MiscUtil.PrintConsole("JsonUtil: " + JsonUtil.GetErrors(FileName))
    return
endif

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...