Reputation: 13
I use Newtonsoft.json to deserialize this json
{
"pdf_info": [
[
-> this is a object {
"order_serial_no": "xxxxx",
// more properties
},
-> this is an array ["xxxx", "x"]
]
]
}
In java I can use the following code to achieve this.
JSONArray pdfArray = JSONArray.parseArray(pdf_info);
String pdfArrayOne = pdfArray.getString(0);
JSONArray jsonArray = JSONObject.parseObject(pdfArrayOne, JSONArray.class);
String jsonData = jsonArray.getString(0);
Pdf pdf = JSONObject.parseObject(jsonData, Pdf.class);
So, how to deserialize this json with newtonsoft.json
Upvotes: 0
Views: 85
Reputation: 1175
Apparently (after removing your comments) this would be the c# class of your object (Copy the json to clipboard -> in Visual Studio 'Edit->paste special->paste json as class' - see more on this)
public class Rootobject
{
public object[][] pdf_info { get; set; }
}
Define this Type and you would be able to deserialize it using:
Newtonsoft.Json.JsonConvert.DeserializeObject<Rootobject>(System.IO.File.ReadAllText(fileName));
Upvotes: 1
Reputation: 1
Firstly -> read the docs.
Secondly:
JObject data = JObject.Parse(jsonText); // deserialize to dict-like object
Upvotes: 0