I got a C# Class:
public class JsonAttachmentModel
{
public Guid AttachmentId { get; set; }
public string FileName { get; set; }
public string ExtentionName { get; set; }
}
and the JSON i retrieve is unwellformatted, it is altogether in one string, like:
{"success":false,"message":"The remote server returned an unexpected response: (413) Request Entity Too Large."},
{"success":true,"attachmentId":"dba60830-46fd-4f51-9cd5-3c20df03988d","fileName":"bz1_20121206113251.PNG","extentionName":".PNG"},
{"success":true,"attachmentId":"3cae3f50-7d70-4183-9a69-80cb6d619dbd","fileName":"bz2_20121206113251.PNG","extentionName":".PNG"},
{"success":true,"attachmentId":"b6c8a524-4f46-4a7a-bcda-70042cb4ca92","fileName":"IammorethanOneKb123_20121206113251.txt","extentionName":".txt"},
{"success":true,"attachmentId":"994dfb9c-a185-4c51-b1f4-1017f991740d","fileName":"Iamonekb_20121206113251.txt","extentionName":".txt"}
So, my question is :
How can I convert this string to List<JsonAttachmentModel>, with the items which only match “success”: true
Use JSON.NET. Check out the Serialization/Deserialization examples from here.
Example from the above documentation –