Click here to Skip to main content
15,884,836 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
Posted
Updated 20-Feb-21 0:23am
Comments
Kenneth Haugland 20-Feb-21 6:14am    
Can we see you attempt? Or is that top secret stuff?

1 solution

Um.
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:
[{"RN":"1","QUERY_ID":"1519852833","QTYPE":"W","SENDERNAME":"Name1","SENDEREMAIL":"xyz@gmail.com"},{"RN":"2","QUERY_ID":"1519834488","QTYPE":"W","SENDERNAME":"Name2","SENDEREMAIL":"xyz2@gmail.com"}]
Contains an array of two instances of a class:
C#
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:
C#
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!
 
Share this answer
 
v2
Comments
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