-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to handle duplicate keys? #8
Comments
No, your question is definitely a good one. I'll include this in the FAQ at some point. In general, you cannot access values of duplicate keys in the same way you would a dictionary, which But there is something you can do.
To access the last value of "key1", just do: VProperty root = VdfConvert.Deserialize(vdf);
Console.WriteLine(root.Value["key1"]); // Prints 'value1'
Console.WriteLine(root.Value["key2"]); // Prints 'value2'
Console.WriteLine(root.Value.Children().Last(x => x.Key == "key1").Value); // Prints 'value3' As an aside, could you tell me where you found the erroneous VDF data you have? Did you find it in the Steam installation directory? |
To add to my previous response, if you need an array of values, just do:
|
I'm closing this issue due to inactivity. If you have further questions, feel free to reopen. |
If anyone else stumbles across this issue and just wants to treat duplicates differently: var json = VdfConvert.Deserialize(text).ToJson(new VdfJsonConversionSettings() { ObjectDuplicateKeyHandling = DuplicateKeyHandling.Ignore, ValueDuplicateKeyHandling = DuplicateKeyHandling.Ignore }); |
@Bluscream Note that your solution only applies when converting a |
There is one misconception about VDF: it's not a dictionary! The best unambiguous way to represent parsed VDF data is to use a list. |
Sorry for the silly question, I'm new to this entire C# scene, and I'm using this parser for a project. As a result, I'm probably being a complete and total idiot and that my issue is common C# knowledge.
If two keys with the same name exist in the same object, they're both used in that object but have the same value. In the VDF formatted file that I'm using, though, they both have different values.
In other words, is it possible to access these values like a numeric array to avoid this issue? Or is there anything else in this parser that lets me do this?
The text was updated successfully, but these errors were encountered: