1

I have a JSON Response which looks something like this. JSONResponse

I am trying to access the value "Hello". I am using Newtonsoft.JSON package to parse and serialize my data. I am able to access all the values, except "Hello" .

Below is a small example of how I dealt with single level arrays like menu3:

JArray dataArr = (JArray)joResponse["menu3"];     //joResponse is my JSONresponse
string[] datalist = dataArr.ToObject<string[]>(); //gave me 1234 and 5678 as string list

Any ideas/logic/resource/example would be greatly appreciated!

0

1 Answer 1

1

It would be much easier for you if you'd create a model class for the JSON response and deserialized the string using it. For example:

public class MyModel {
    public string Menu1 { get; set; }
    public string Menu2 { get; set; }
    public List<int> Menu3 { get; set; }
    public string Menu4 { get; set; }
    public List<string> Menu5 { get; set; }
}

Then, in the class you receive your JSON string:

    var myObj = JsonConvert.DeserializeObject<MyModel>(jsonString);
    // Access any property through myObj object
    var menu1 = myObj.Menu1;
Sign up to request clarification or add additional context in comments.

2 Comments

I keep getting the following error. "Value cannot be null. Parameter name: Value"
@CodeBreaker please edit your question with the code you're currently using and a sample JSON

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.