Reputation: 165
Good day,
I have a RavenDB JSON Document in which one field ("Info") contains a string that looks like this:
"{\"value1\":\"9\", \"value2\": \"dog\", ....}"
I would like to remove the escaping "\"
characters so it will be recognized as a JSON List by RavenDB.
However, I have tried updating the Documents with
newString = oldString.Replace("\\", "")
,
newString = oldString.Replace(@"\", "")
and newString = oldString.Trim(new Char[] { @"\" })
but it does not work. After applying these above mentioned methods the string looks unchanged.
Please see below the full code:
while(true)
{
var result = session.Query<Documents>()
.Take(1000).Skip(i)
.ToList();
if (result.Count == 0)
break;
foreach (var r in result)
{
string rInfo = r.Info.ToString();
rInfo = rInfo.Replace("\\", "");
PATCHED_Doc r_Doc = new PATCHED_Doc()
{
Info = rInfo,
Value = "test",
Id = r.Id,
Date = r.Date,
};
session.Store(r_Doc);
session.SaveChanges();
}
session.SaveChanges();
i += result.Count;
}
public class PATCHED_Doc
{
public string Info { get; set; }
public string Value { get; set; }
public int Id { get; set; }
public string Date { get; set; }
}
Thank you in advance for helping.
Upvotes: 0
Views: 707
Reputation: 3281
You need to Parse the JSON into an object and then hand it over to Raven DB. Strings are treated as strings. Use JSON.NET library to parse it into Anonymous objects. Change your Info property to type of object. Then Assign the anonymous object to the Info property.
Upvotes: 1