I have an array of objects like this in json
format:
{"results":[{"SwiftCode":"","City":"","BankName":"Deutsche Bank","Bankkey":"10020030","Bankcountry":"DE"},{"SwiftCode":"","City":"10891 Berlin","BankName":"Commerzbank Berlin (West)","Bankkey":"10040000","Bankcountry":"DE"}]}
What I want to get is a object[]
in C#, where one object contains all the data what is in one json object. The thing is, I can NOT make a class with the properties of this object like here:
public class Result
{
public int SwiftCode { get; set; }
public string City { get; set; }
// .
// .
public string Bankcountry { get; set; }
}
Because I get everytime different results back, but I know it's always an array of objects. Someone knows how I could manage to get an array of objects back?
EDIT
I have to pass this object to powershell via WriteObject(results)
. So the ouput should only be the object IN the array
.
Though this is an old question, I thought I'd post my answer anyway, if that helps someone in future
This solution uses Newtonsoft library, don't forget to include
using Newtonsoft.Json.Linq;
string jsonData1=@"[{""name"":""0"",""price"":""40"",""count"":""1"",""productId"":""4"",""catid"":""4"",""productTotal"":""40"",""orderstatus"":""0"",""orderkey"":""123456789""}]";
couldnot parse , if the vaule is a string..
look at name : meals , if name : 1 then it will parse
Use
NewtonSoft JSON.Net
library.Hope this helps.
I have just got an solution a little bit easier do get an list out of an JSON object. Hope this can help.
I got an JSON like this:
And made some types like this
and the "magic" part
Use newtonsoft like so:
I believe this is much simpler;