Reputation: 323
I am getting below mentioned error when assgining JSON object like this:
pushNotification.NotificationMessageList = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(response);
Here NotificationMessageList is a Dictionary as mentioned below:
Dictionary<string, string> NotificationMessageList { get; }
Error: Property or indexer 'IPushNotifications.NotificationMessageList' cannot be assigned to -- it is read only (CS0200)
Can anyone assist me to fix the issue?
Upvotes: 2
Views: 523
Reputation: 29036
You have defined the Dictionary
as read-only property
, So it won't allow you to assign values if you really want to assign means to make it as normal property, include set; which means the property definition will be like this:
Dictionary<string, string> NotificationMessageList { get; set;}
The getter and setter are known as Accessors, you can read more about them from This MSDN Blog
Upvotes: 4
Reputation: 788
obviously you can't deserialise response into a dictionary. would you consider using JObject instead? it's easy to use and quite close to dictionary.
var o = JObject.Parse(response);
//to get the value
var value = o["key_name"].Value<type>()
Upvotes: 0