0

Ive got a JSON string im sending from my web client to my webapi. This JSON string kind of dynamically formed.

So I want to know if there is a way if I can convert this JSON string into a list/array of dynamic objects. So can handle it along the same line as:

var DynamicArray = WhatEverJSONConvertor(JSONString);

for (int i = 0; i < DynamicArray.length; i++)
{
      Console.WriteLine(DynamicArray[i].AFieldInTheObject);
}

Is this possible? What JSON convertor would I use this to accomplish this?

Thanks

2

1 Answer 1

1

Why dont you use JSon.net and for your json response use dynamic :

dyanmic [] jsonresponseArray= WhatEverJSONConvertor(JSONString);

for (int i = 0; i < DynamicArray.length; i++)
{
      Console.WriteLine(jsonresponseArray[i].AFieldInTheObject);
}

....
public dynamic[] WhatEverJSONConvertor(string json){
   // parse and create a dynamic type object
}

You need to ensure if the field exists, such as extension method could do.

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

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.