Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# Serialize and json

Tags:

json

arrays

c#

I tried to deserialize:

JsonConvert.DeserializeObject<ContentModel>("{\"Message\":\"asdf\",\"Attachments\":[\"dummy.pdf\",\"unnamed.jpg\"]}"),

Where the content model:

public class ContentModel
{
    public string Message { get; set; }
    public string ContentType { get; set; }
    public string[] Attachments { get; set; }
}

But the deserialization failed due to the array of string in the Attachments.

like image 822
LittleFunny Avatar asked Dec 08 '25 09:12

LittleFunny


1 Answers

The character you are using in between of \"dummy.pdf\" and \"unnamed.jpg\" is not really a comma! it just looks like to be a comma! remove it and replace it with , .

Update
As @dbc mentioned, The character being used currently in your code is FULLWIDTH COMMA.

like image 125
Shahryar Saljoughi Avatar answered Dec 10 '25 22:12

Shahryar Saljoughi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!