Saving dictionaries can unintentionally generate invalid data files
See original GitHub issuevoid Test()
{
var dicc = new Dictionary<int, Vector3>()
{
[22] = new Vector3(-12, 323, 432.43f),
[55] = new Vector3(-1, 0, 100),
[-100] = new Vector3(Mathf.PI, Mathf.PI, Mathf.PI),
};
var file = new DataFile("test", autoSave: true);
file.Set("dicc boi", dicc);
}
That code generates this file:
dicc boi:
22:
x: -12
y: 323
z: 432.43
55:
x: -1
y: 0
z: 100
-100:
x: 3.141593
y: 3.141593
z: 3.141593
Notice the key called “-100”. Keys are not allowed to begin with -
, as that character is reserved for list nodes. Trying to read the file later will throw errors. This can also happen when using DataFile.SaveAsDictionary().
The solution is probably to allow -
in key nodes, and determine what is a list node by the absence of :
.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
How to store a dictionary as a separate file, and read ...
Is there a way to do this. I tried to make a text file "gene_data1.txt" that just included the dictionary. So, the contents...
Read more >Create a Dictionary in Python – Python Dict Methods
In this article, you will learn the basics of dictionaries in Python. You will learn how to create dictionaries, access the elements inside ......
Read more >Save a dictionary to a file
A dictionary in Python is a collection where every value is mapped to a key. They are unordered, mutable and there is no...
Read more >Python Save Dictionary To File [4 Ways]
Learn to save a dictionary to a file in Python. Write dict objects to text, csv, and binary files using the pickle, json,...
Read more >How to use sessions
The session data will be stored using Django's tools for cryptographic signing ... The same invalidation happens if the client storing the cookie...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed in
2487cce
and will be in the next release. Dictionaries, when serialized with their keys as children, will always surround the keys in quotes.In
4934481
I fixed this in a much nicer way. Dictionaries now check if their key is a valid SUCC key, and if not, they serialize as an array of KeyValuePair.