mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-29 22:32:02 +00:00
[C#] support Json Serialization (#5752)
* support json serialization
* fix invalid json format.
* string must be written with double quotes.
* remove commma after the last object member.
* fix indent
* Revert "fix invalid json format."
This reverts commit d6820ed50c.
* quated string value.
* add cs-gen-json-serializer flag.
* fix preprocessor indent
* ENABLE_JSON_SERIALIZATION -> ENABLE_JSON_SERIALIZATION_TEST
* share TestBuffer method
* remove ENABLE_JSON_SERIALIZATION
* remove duplicated test data
* [windows] add nuget restore and copy test data.
* [docker mono] share msbuild settings with windows. add nuget restore and copy test data.
* add some note for json api.
This commit is contained in:
@@ -151,15 +151,25 @@ public struct MonsterExtra : IFlatbufferObject
|
||||
|
||||
public class MonsterExtraT
|
||||
{
|
||||
[Newtonsoft.Json.JsonProperty("d0")]
|
||||
public double D0 { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("d1")]
|
||||
public double D1 { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("d2")]
|
||||
public double D2 { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("d3")]
|
||||
public double D3 { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("f0")]
|
||||
public float F0 { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("f1")]
|
||||
public float F1 { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("f2")]
|
||||
public float F2 { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("f3")]
|
||||
public float F3 { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("dvec")]
|
||||
public List<double> Dvec { get; set; }
|
||||
[Newtonsoft.Json.JsonProperty("fvec")]
|
||||
public List<float> Fvec { get; set; }
|
||||
|
||||
public MonsterExtraT() {
|
||||
@@ -174,6 +184,13 @@ public class MonsterExtraT
|
||||
this.Dvec = null;
|
||||
this.Fvec = null;
|
||||
}
|
||||
|
||||
public static MonsterExtraT DeserializeFromJson(string jsonText) {
|
||||
return Newtonsoft.Json.JsonConvert.DeserializeObject<MonsterExtraT>(jsonText);
|
||||
}
|
||||
public string SerializeToJson() {
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user