I am new to c# and I am trying to deserialize a json source with C#, using the script component task of SSIS.
The source that I am getting is like this one:
[{
"listing_id" : "1",
"customer_id" : "2",
"state" : "Online",
"rooms" : ["kitchen","Bedroom"],
"furniture" : ["Couch","chair"],
},
{
"listing_id" : "2",
"customer_id" : "5",
"state" : "Online",
"rooms" : ["kitchen","Bedroom"],
"furniture" : ["Couch","chair"]
}
]
based on json2csharp.com, I got the C# class of the json
publicclassRootObject{publicstring listing_id {get;set;}publicstring customer_id {get;set;}publicstring state {get;set;}publicList<string> rooms {get;set;}publicList<string> furniture {get;set;}}
and the C# code
try { ListingBuffer.AddRow(); ListingBuffer.ListingId = outPutResponse.listing_id; ListingBuffer.CustomerId = outPutResponse.customer_id; ListingBuffer.State = outPutResponse.state; foreach (string rm in outPutResponse.rooms) { RoomListingBuffer.AddRow(); RoomListingBuffer.ListingId = outPutResponse.listing_id; RoomListingBuffer.Description = rm; } foreach (string f in outPutResponse.furniture) { RoomListingBuffer.AddRow(); RoomListingBuffer.ListingId = outPutResponse.listing_id; RoomListingBuffer.Description = f; } }But I am getting the follow error:
Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'ScriptMain+RootObject' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path '', line 1, position 1.
Probably the problem is that the JSON data starts with [ & ands with ] , but I haven't find the solution to the errors
Any clues? Thank you in advance