deserialization

Deserialize CSV string to an C# Object

爱⌒轻易说出口 提交于 2021-02-10 13:16:36
问题 I have a response from Jira API , require to be deserialized into data model: com.atlassian.greenhopper.service.sprint.Sprint@40675167[id=10151,rapidViewId=171,state=CLOSED,name=Sprint 37.1,startDate=2015-07-30T16:00:22.000+03:00,endDate=2015-08-13T16:00:00.000+03:00,completeDate=2015-08-13T14:31:34.343+03:00,sequence=10151] This is actually the information of current sprint for issue. I need to deserialize it to a model like: public class Model { public string name { get; set; } ... } I have

Deserialize JSON which can have different objects under same property name

最后都变了- 提交于 2021-02-09 11:12:12
问题 I'm using JSON.NET to deserialize JSON responses from HTTP queries, but I'm stuck with an issue. That's because the response can send two types of object under same property, as shown below: 1st case sample (most common): { "type": "myType", "tid": 4, "action": "myAction", "method": "myMethod", "result": { "success": true, "total": 4, "records": [ { "id": 4, "nome": "PRIMEIRO NOME", "sigla": "PN" }, { "id": 1974, "nome": "SEGUNDO NOME", "sigla": "SN" }, { "id": 2584, "nome": "TERCEIRO NOME",

Deserialize JSON which can have different objects under same property name

偶尔善良 提交于 2021-02-09 11:05:56
问题 I'm using JSON.NET to deserialize JSON responses from HTTP queries, but I'm stuck with an issue. That's because the response can send two types of object under same property, as shown below: 1st case sample (most common): { "type": "myType", "tid": 4, "action": "myAction", "method": "myMethod", "result": { "success": true, "total": 4, "records": [ { "id": 4, "nome": "PRIMEIRO NOME", "sigla": "PN" }, { "id": 1974, "nome": "SEGUNDO NOME", "sigla": "SN" }, { "id": 2584, "nome": "TERCEIRO NOME",

strlen() gives wrong size cause of null bytes in array

情到浓时终转凉″ 提交于 2021-02-08 12:11:46
问题 I have a dynamic char array that was deserialized from a stream. Content of char *myarray on the file (with a hexal editor) : 4F 4B 20 31 32 20 0D 0A 00 00 B4 7F strlen(myarray) returns 8, (must be 12) 回答1: strlen(myarray) returns the index of the first 00 in myarray . 回答2: strlen counts the characters up to the first 0 character, that's what it's for. If you want to know the length of the deserialized array, you must get that from somewhere else, the deserialization code should know how

How do I deserialize a JSON array using Newtonsoft.Json

久未见 提交于 2021-02-07 04:43:46
问题 [ { "receiver_tax_id":"1002", "total":"6949,15", "receiver_company_name":"Das Company", "receiver_email":"info@another.com", "status":0 }, { "receiver_tax_id":"1001", "total":"39222,49", "receiver_company_name":"SAD company", "receiver_email":"info@mail.com", "status":1 } ] Hi, this is my Json data, but I can't deserialize it. I want to check only "status" value. (first object "status" 0, second object "status" 1). Example definition: public class Example { [JsonProperty("receiver_tax_id")]

c# Deserialize unlabelled JSON array

▼魔方 西西 提交于 2021-02-05 09:33:28
问题 I am attempting to deserialize a piece of JSON with a specific structure like so: { "label1": "value1", "label2": [ [ [ "concept_id_1", "concept_1" ], score_1 ], [ [ "concept_id_2", "concept_2" ], score_2 ], …… ], "label3": "value3", "label4": "value4" } For what it's worth, the scores are floats and everything else is a string. The number of returned concepts under "label2" is variable. I'm attempting to deserialize it using JSON.net. The only content I actually care about is the inside nest

c# Deserialize unlabelled JSON array

半腔热情 提交于 2021-02-05 09:33:14
问题 I am attempting to deserialize a piece of JSON with a specific structure like so: { "label1": "value1", "label2": [ [ [ "concept_id_1", "concept_1" ], score_1 ], [ [ "concept_id_2", "concept_2" ], score_2 ], …… ], "label3": "value3", "label4": "value4" } For what it's worth, the scores are floats and everything else is a string. The number of returned concepts under "label2" is variable. I'm attempting to deserialize it using JSON.net. The only content I actually care about is the inside nest

How to parse a json field that may be a string and may be an array with Jackson

微笑、不失礼 提交于 2021-02-05 06:49:05
问题 I have a json field that is string when there's one value: { "theField":"oneValue" } or array when there are multiple values: { "theField": [ "firstValue", "secondValue" ] } And then I have my java class that uses com.fasterxml.jackson.annotation.JsonCreator: public class TheClass { private final List<String> theField; @JsonCreator public TheClass(@JsonProperty("theField") List<String> theField) { this.theField = theField; } } The problem is that the code does not work when the incoming field

Jackson: Is there a way to ignore 0/1 on Boolean deserialization?

依然范特西╮ 提交于 2021-02-05 05:52:08
问题 I have a JSON object with a Boolean property that needs to allow only true or false during the deserialization. Any value different of true and false should throw an exception. How can I do that? e.g.: Valid json: { "id":1, "isValid":true } Invalid json: { "id":1, "isValid":1 } Update I tried what @Michał Ziober proposed and it worked fine. As I'm implementing a Spring application (with Webflux) I just had to configure in a different way. I'm posting here what I did: Create a Configuration

Deserializing map key with Gson expects an object

∥☆過路亽.° 提交于 2021-02-05 05:32:29
问题 I get the error: Exception in thread "main" com.google.gson.JsonParseException: Expecting object found: "com.shagie.app.SimpleMap$Data@24a37368" when trying to deseralize a Map that uses non-trivial keys: package com.shagie.app; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import java.util.HashMap; public class SimpleMap { public static void main(String[] args) { Wrapper w = new Wrapper(); w.m.put(new Data("f", 1), new Data("foo", 3)); w.m.put(new Data("b", 2), new Data(