Remove apostrophes from json string property
Hi I try deserialize this string with JSON.NET.
String look like this:
{
"mishelka.sk": {
"idUser": 15289422,
"nick": "MiShelKa.Sk",
"photo": "1",
"sex": 2,
"photoAlbums": 4,
"videoAlbums": 3,
"sefNick": "mishelka.sk",
"profilPercent": 78,
"emphasis": false,
"age": 14,
"isBlocked": false,
"PHOTO": {
"normal": "http://u.aimg.sk/fotky/1528/94/n_15289422.jpg?v=4",
"medium": "http://u.aimg.sk/fotky/1528/94/m_15289422.jpg?v=4",
"24x24": "http://u开发者_StackOverflow中文版.aimg.sk/fotky/1528/94/s_15289422.jpg?v=4"
},
"PLUS": {
"active": false,
"activeTo": "0000-00-00"
},
"LOCATION": {
"idRegion": "10",
"regionName": "zahraničie",
"idCity": "182",
"cityName": "Zahraničie - GB"
},
"STATUS": {
"isLoged": false,
"isChating": false,
"idChat": 0,
"roomName": "",
"lastLogin": 1294767618
},
"PROJECT_STATUS": {
"photoAlbums": 4,
"photoAlbumsFavs": 1,
"videoAlbums": 3,
"videoAlbumsFavs": 33,
"videoAlbumsExts": 0,
"blogPosts": 0,
"emailNew": 1,
"postaNew": 0,
"clubInvitations": 0,
"dashboardItems": 54
},
"STATUS_MESSAGE": {
"statusMessage": "Jaj henka zabila si dneska hah",
"addTime": "1294678134"
},
"isFriend": false,
"isIamFriend": false
},
"mishel431": {
"idUser": 18327105,
"nick": "mishel431",
"photo": "1",
"sex": 2,
"photoAlbums": 1,
"videoAlbums": 0,
"sefNick": "mishel431",
"profilPercent": 98,
"emphasis": false,
"age": 15,
"isBlocked": false,
"PHOTO": {
"normal": "http://u.aimg.sk/fotky/1832/71/n_18327105.jpg?v=5",
"medium": "http://u.aimg.sk/fotky/1832/71/m_18327105.jpg?v=5",
"24x24": "http://u.aimg.sk/fotky/1832/71/s_18327105.jpg?v=5"
},
"PLUS": {
"active": false,
"activeTo": "0000-00-00"
},
"LOCATION": {
"idRegion": "1",
"regionName": "Banskobystrický kraj",
"idCity": "70",
"cityName": "Lučenec"
},
"STATUS": {
"isLoged": false,
"isChating": false,
"idChat": 0,
"roomName": "",
"lastLogin": 1294760188
},
"PROJECT_STATUS": {
"photoAlbums": 1,
"photoAlbumsFavs": 0,
"videoAlbums": 0,
"videoAlbumsFavs": 0,
"videoAlbumsExts": 0,
"blogPosts": 0,
"emailNew": 1,
"postaNew": 0,
"clubInvitations": 0,
"dashboardItems": 14
},
"STATUS_MESSAGE": {
"statusMessage": " I hate "apple" lalala:(",
"addTime": "1293656085"
},
"isFriend": false,
"isIamFriend": false
}
}
I try deserialize this string into dic everything is ok, but I have one problem.
Here is it:
"STATUS_MESSAGE": {
"statusMessage": " I hate "apple" lalala:(",
"addTime": "1293656085"
},
statusMessage property can consit apostrophes,this cause invalid exception json string. I would like elegant remove apostrophs from string property statusMessage in all json string.
Any advice. Use regExp. I am not strong in this domain.
this part is deserialize in this class:
[Export]
public class StatusMessage : INotifyPropertyChanged
{
#region Private Fields
private string _message;
#endregion
#region Properties
[JsonProperty("statusMessage")]
public string Message
{
get { return _message; }
set
{
if (_message != value)
{
_message = value;
NotifyPropertyChanged("Message");
}
}
}
[JsonProperty("addTime")]
public string AddTime { get; set; }
#endregion
#region Implementation of INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
#endregion
#region Public methods
public void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
The generator of your Json string should escape the quotes using backslash.
Check out the spec on Json website That way you don't have to worry about wrongly formed Json string
精彩评论