json-deserialization

JsonSerializer silently fails to deserialize my object

…衆ロ難τιáo~ 提交于 2020-08-10 22:46:28
问题 I am trying to store my relational object in a JSON file rather than a SqlLite database as I think it suits better for what I am trying to do. I am using Microsoft's System.Text.Json.Serialization but that does not seem to be working. My object is saved to a JSON text file with this: var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, WriteIndented = true }; options.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)); // Enums as

Gson deserialize Array of Integers in kotlin

馋奶兔 提交于 2020-08-10 19:42:05
问题 Normally, when I deserialize a json-String I use something like this: val result = gson.fromJson<myObject>(json, object : TypeToken<myObject>() {}.type) But now I want to deserialize a simple List of Int and I cannot build an object for that. The json-String is extremely simple and looks like this: [1,35,37,255] and I would like to save it into a List but val result = gson.fromJson<List<Int>>(json, object : TypeToken<List<Int>>() {}.type) does not work because there is no object. How should I

Deserialize inconsistent JSON property

╄→尐↘猪︶ㄣ 提交于 2020-08-09 08:02:11
问题 Hopefully someone can help me with the following inconsistency occurring in a large JSON file that I am attempting to deserialize using Newtonsoft.Json. One of the properties of the object occasionally appears as: "roles": [ { "field1" : "value", "field2" : "value" } ] While other times that same property appears as: "roles": { "roles": [ { "field1" : "value", "field2" : "value" } ] } For reference, this property is implemented in its class as: [JsonProperty("roles")] public List<Role> Roles

Flutter Dart deserialize a json with dynamic key but structured values into Map<String, ModelClass>

回眸只為那壹抹淺笑 提交于 2020-07-23 08:13:06
问题 Is it possible to deserialize a json with dynamic key but structured values into Map in flutter dart. I am having a json like { "data" : { "apple":{"qty":5, "price":100}, "orange":{"qty":2, "price":40}, } } And I want this to deserialize in flutter/dart to a model class below class Data { Map<String, Item> itemMap; factory Data.fromJson(Map<String,dynamic> json) { itemMap : json["data"]; //How to parse. } } class Item { int qty; int price; } I have read through a medium blog and even this