-
Notifications
You must be signed in to change notification settings - Fork 88
Open
Description
This is not issue, I think it good idea if you can add https://app.quicktype.io to the Readme, it parse JSON and generate the Class, it useful for known Json and save times writing the class.
Short how to:
- open the website
- paste your json
- set
Output featurestoJust Typesor other - set
Otheroptions if needed* (detect boolean/int to false), ex:{"IwantAsString" : "12345"}or this parser will throw error because the parser try to convert"12345"(with quote) to long. But you can also fix the parser on Line 163 by prepend the linejson = json.Trim('"'); - Copy generated code to you project
Example how it can be very useful
Json code
{
"FirstKey": {
"SecondKey": "val",
"ThirdKey": [1, 2]
}
}Generated class
namespace projectNamespace
{
public partial class MyJsonClass
{
public FirstKey FirstKey { get; set; }
}
public partial class FirstKey
{
public string SecondKey { get; set; }
public List<long> ThirdKey { get; set; }
}
}Access it
var jsonClass = File.ReadAllText("file.json").FromJson<MyJsonClass>();
jsonClass.FirstKey.SecondKey = "test";
jsonClass.FirstKey.ThirdKey.Add(3);
// VS
var jsonClass = File.ReadAllText("file.json").FromJson<Dictionary<string, Dictionary<string, string>>>();
jsonClass["FirstKey"]["SecondKey "] = "test"
jsonClass["FirstKey"]["ThirdKey"]... problematicMetadata
Metadata
Assignees
Labels
No labels