-3
string sample = "{\"STACK_SIZE\":4,\"thes_stack\":[4,4]}";

how can I parse it using RE in C#?

4

1 Answer 1

2

First of all this isn't a valid JSON, remove the backslashes. Second, using a library like JSON.NET you can parse your sample.

string sample = "{"STACK_SIZE":4, "thes_stack":[4,4]}";

var parsed = JsonConvert.DeserializeObject<dynamic>(sample);

that will parse it into a dynamic type, if you want something more strongly typed create your own class:

class StackInfo
{
    public int STACK_SIZE {get; set;}
    public int[] thes_stack {get; set;}
}

then you can deserialize into it:

string sample = "{"STACK_SIZE":4, "thes_stack":[4,4]}";

var parsed = JsonConvert.DeserializeObject<StackInfo>(sample);

But since you didn't put exactly what you need or exactly what your problem is with the suggestions in the comments no one can really help you.

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

4 Comments

That really helped me in understanding the process and well i am going to implement it as we were at holiday.thanks alot
"backslashes" here for the c# compiler to escape quotes. They are not part of JSON.
@Kamarey Ya I noticed, seems I was sleepy, anyways, fixed it.
Guys i knew that but I did not notice as I was in search of cored code Thanks again to all

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.