Reputation: 1472
I have a json file given below
var json={
"AttachmentInfo":[
{
"FileName":"sign_encrypted_.pdf",
"FilePath":"b89ddfa7-af16-4e4d-b16b-b6d49db9b91f",
"FileSize":104504.0,
"FileExtention":".pdf",
"FileType":2
}
]
}
I need to get the FilePath from the above json.
I tried
var filePath=(string)json["AttachmentInfo"].SelectToken("FilePath");
but only null value return.
Thanks in advance for help.
Upvotes: 1
Views: 596
Reputation: 695
First, try to deserialize JSON and then you can access it like dynamic object, here is a snipe code:
string json = ...;
var serializer = new JavaScriptSerializer();
serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
dynamic obj = serializer.Deserialize(json, typeof(object));
var filePath = obj.AttachmentInfo[0].FilePath;
Upvotes: 1