3

I'm just curious if there's a way to store JSON Array to dynamic List<> ?

For example :

Here's my JSON Array :

[ { "trx_id": 1, "bank_id": 50 } ]

I want to assign those JSON Array to a new List<>. Here's my code :

var dynObjectsList = new List<dynamic>(); // I want to assign both properties name and properties value to this variable

Here's the reason why i want it this way :

Basically, I'm building a client API to consume a web service. Let's say I successfully consumed web service A and web service B. I need to store the value returned from web service A and web service B in a separated List<>, so I can use Linq for JOIN-ing the List<>. I can store it easily if I got the model for each web service, but unfortunately I don't have it, so I need to build the List<> manually

I've been gooling it for awhile, but no luck for me.

Is there any way to do this?

Thank you

2
  • could you please explain why do you need JSON Array as a dynamic variable ? Commented Jul 26, 2016 at 7:49
  • hi @Vladimir, see my edited post above , thank you Commented Jul 26, 2016 at 7:58

1 Answer 1

8

Using newtonsoft.json nuget package you could do the following:

var list = JsonConvert.DeserializeObject<List<dynamic>>("[{ \"trx_id\": 1, \"bank_id\": 50 }]");
Sign up to request clarification or add additional context in comments.

1 Comment

Man, thanks so much, I didn't expect it that way, so many distraction in my head @_@. Thanks dude

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.