0

I have an array in JSON format:

    "[    
        {        
            \"acrescimo\": null,        
            \"tipo\": \"A\",        
            \"nome\": \"TABELA PRIME\",        
            \"ultima_alteracao\": \"2016-05-25 17:32:55\",        
            \"excluido\": false,        
            \"id\": 3801,        
            \"desconto\": null    
        },    
        {        
            \"acrescimo\": null,        
            \"tipo\": \"A\",        
            \"nome\": \"TABELA SPCAP-SPINT-SUL DISTR\",        
            \"ultima_alteracao\": \"2016-05-25 17:33:41\",        
            \"excluido\": false,        
            \"id\": 3803,        
            \"desconto\": null    
        }
   ...

I need to consume one Json in my class:

public class GetPrecoBO
    {
        public int id { get; set; }
        public string nome { get; set; }
        ...
        public DateTime ultima_alteracao { get; set; }
    }

I searched the forum but did not find something to help me in particular. How do I return the array data in my class?

2
  • Usually, you'd look at finding a means to convert from the JSON string to an Array of Dictionaries, and then use those Dictionaries to construct your object. (But I am not a C# coder.) Commented Jun 9, 2016 at 15:28
  • Anyway, you should probably use the term deserialize to indicate what you want to do with the JSON string. Commented Jun 9, 2016 at 15:29

2 Answers 2

2

I'm not sure if I understand this correctly, but are you saying you need to deserialize your JSON array into your C# object type? If so, Newtonsoft JSON.Net Nuget package is the way to go and can serialize and deserialize for you.

Sign up to request clarification or add additional context in comments.

2 Comments

Exactly because after deserialize will do an insert in my database
Perfect, than this is they way you want to go.
0

Using Json.NET you could deserialize the object as an IEnumerable of the GetPrecoBO object.

var array = JsonConvert.DeserializeObject<IEnumerable<GetPrecoBO>(<jsonString>);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.