Click here to Skip to main content
14,937,132 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Deserialized jsonobject into string.Need to split as seperate values

What I have tried:

Deserialized jsonobject into string.Need to split as seperate values
Updated 20-Feb-21 0:23am
Kenneth Haugland 20-Feb-21 6:14am
Can we see you attempt? Or is that top secret stuff?

1 solution

You do realize that JSON is a string to start with, but that the whole idea of JSON is that it's a "container format" - it holds information which is deserialized into string and non-string classes, including dates, integers, arrays, classes, and so forth.

For example, the JSON string:
Contains an array of two instances of a class:
public class Example
    public int  RN { get; set; }
    public int QUERY_ID { get; set; }
    public string QTYPE { get; set; }
    public string SENDERNAME { get; set; }
    public string SENDEREMAIL { get; set; }
Deserializing the JSON would give you an array of Example:
Example[] data = JsonConvert.DeserializeObject<Example[]>(myJSON);

If it deserialized to a single string, then there wasn't a whole lot of point in using JSON in the first place!
Kenneth Haugland 20-Feb-21 7:31am
Tothe op: Copy your Json string into a Visual studio class using: Edit-> Paste Special -> As Json class. That generates the class for you.
OriginalGriff 20-Feb-21 7:43am
Pity I can't upvote comments - I never knew it did that! :thumbsup:

Very handy - I've always used one of the online JSON to C# converters.
Kenneth Haugland 20-Feb-21 11:48am
I found it to be lightning-fast to use, compared to online versions too.
Richard MacCutchan 20-Feb-21 8:03am
Wow, cool tip Kenneth. I wish I had found that a few years ago when I had a very complex set of JSON to process.
Kenneth Haugland 20-Feb-21 11:47am
It might be a rather recent addition to Visual Studio, I have not noticed it before either. But having to use a deserializer forced me to o some googling and then I found this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900