I have following json (a part from large json response) returned by google contacts api v3
"entry": [
{
"id": {
"$t": "http://www.google.com/m8/feeds/contacts/zahidmadeel%40gmail.com/base/a769270d0bdc93"
},
"gd$etag": "\"R38-fDVSLit7I2A9WhFbEUkNQw0.\"",
"updated": {
"$t": "2013-09-02T18:44:56.154Z"
},
"app$edited": {
"xmlns$app": "http://www.w3.org/2007/app",
"$t": "2013-09-02T18:44:56.154Z"
},
"category": [
{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://schemas.google.com/contact/2008#contact"
}
],
"title": {
"$t": "Ruairi Browne"
},
"link": [
{
"rel": "http://schemas.google.com/contacts/2008/rel#photo",
"type": "image/*",
"href": "https://www.google.com/m8/feeds/photos/media/zahidmadeel%40gmail.com/a769270d0bdc93?v=3.0"
},
{
"rel": "self",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/zahidmadeel%40gmail.com/thin/a769270d0bdc93?v=3.0"
},
{
"rel": "edit",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/zahidmadeel%40gmail.com/thin/a769270d0bdc93?v=3.0"
}
],
"gd$name": {
"gd$fullName": {
"$t": "Ruairi Browne"
},
"gd$givenName": {
"$t": "Ruairi"
},
"gd$familyName": {
"$t": "Browne"
}
},
"gd$email": [
{
"address": "ruairi.browne@mhlabs.net",
"primary": "true",
"rel": "http://schemas.google.com/g/2005#other"
}
]
},
{
"id": {
"$t": "http://www.google.com/m8/feeds/contacts/zahidmadeel%40gmail.com/base/e268ff0bc63d0b"
},
"gd$etag": "\"QH89ezVSLyt7I2A9Wx5VE0gOTgY.\"",
"updated": {
"$t": "2010-10-06T08:48:41.163Z"
},
"app$edited": {
"xmlns$app": "http://www.w3.org/2007/app",
"$t": "2010-10-06T08:48:41.163Z"
},
"category": [
{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://schemas.google.com/contact/2008#contact"
}
],
"title": {
"$t": ""
},
"link": [
{
"rel": "http://schemas.google.com/contacts/2008/rel#photo",
"type": "image/*",
"href": "https://www.google.com/m8/feeds/photos/media/zahidmadeel%40gmail.com/e268ff0bc63d0b?v=3.0"
},
{
"rel": "self",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/zahidmadeel%40gmail.com/thin/e268ff0bc63d0b?v=3.0"
},
{
"rel": "edit",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/zahidmadeel%40gmail.com/thin/e268ff0bc63d0b?v=3.0"
}
],
"gd$email": [
{
"address": "salah@cirinpharma.com",
"primary": "true",
"rel": "http://schemas.google.com/g/2005#other"
}
]
}]
and I have created following classes so that this response could be deserialized in .NET objects
public class Entry
{
[JsonProperty("id")]
public Id Id { get; set; }
[JsonProperty("gd$etag")]
public string GdEtag { get; set; }
[JsonProperty("updated")]
public Updated Updated { get; set; }
[JsonProperty("gd$name")]
public GdName GdName { get; set; }
[JsonProperty("gd$email")]
public List<GdEmail> GdEmail { get; set; }
[JsonProperty("gContact$website")]
public List<GContactWebsite> GContactWebsite { get; set; }
[JsonProperty("gContact$groupMembershipInfo")]
public List<GContactGroupMembershipInfo> GContactGroupMembershipInfo { get; set; }
}
public class Feed
{
[JsonProperty("xmlns")]
public string Xmlns { get; set; }
[JsonProperty("xmlns$openSearch")]
public string XmlnsOpenSearch { get; set; }
[JsonProperty("xmlns$gContact")]
public string XmlnsGContact { get; set; }
[JsonProperty("xmlns$batch")]
public string XmlnsBatch { get; set; }
[JsonProperty("xmlns$gd")]
public string XmlnsGd { get; set; }
[JsonProperty("gd$etag")]
public string GdEtag { get; set; }
[JsonProperty("id")]
public Id Id { get; set; }
[JsonProperty("title")]
public Title Title { get; set; }
[JsonProperty("author")]
public List<Author> Author { get; set; }
[JsonProperty("generator")]
public Generator Generator { get; set; }
[JsonProperty("openSearch$totalResults")]
public OpenSearchTotalResults OpenSearchTotalResults { get; set; }
[JsonProperty("openSearch$startIndex")]
public OpenSearchStartIndex OpenSearchStartIndex { get; set; }
[JsonProperty("openSearch$itemsPerPage")]
public OpenSearchItemsPerPage OpenSearchItemsPerPage { get; set; }
[JsonProperty("entry")]
public List<Entry> Entry { get; set; }
}
public class GoogleContactModel
{
[JsonProperty("version")]
public string Version { get; set; }
[JsonProperty("encoding")]
public string Encoding { get; set; }
[JsonProperty("feed")]
public Feed Feed { get; set; }
}
but the data is not properly de-serialized into c# objects. The problem arises whenever there is $
in json property name. Although, I have decorated each property with JsonProperty
attribute accordingly, but still json properties with $
are not converted to relevant data in .NET objects. How can I accomplish this?
EDIT
I am not deserializing response myself. I am using rest sharp to make api calls and response is deserialized by restsharp on the following line of code
response = restClient.Execute<GoogleContactModel>(restRequest);
and I believe rest sharp uses Json.NET on the backend for serialization/deserialization
Edit2 I just googled a bit and found that restsharp does not use Json.NET for serialization/deseirialization. And it has its own attribute called DeserializeAs
as equivalent to JsonProperty
in Json.Net. I replaced all JsonProperty
attributes with DeserializeAs
attributes but it still does not work.