Reputation: 91
I have a WCF service that returns database tables in JSON format. SeralizeObject adds unicode to my httpresponse, how can i remove this?
Code:
using (var db = new newTestDBContext())
{
var query = from b in db.Roads
orderby b.roadID
select b;
Road rr = query.First();
var serializerSettings = new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects };
return JsonConvert.SerializeObject(rr, Formatting.Indented, serializerSettings);
Reponse:
"{\u000d\u000a \"$id\": \"1\",\u000d\u000a \"roadparts\": [\u000d\u000a {\u000d\u000a \"$id\": \"2\",\u000d\u000a \"Road\": {\u000d\u000a
Upvotes: 3
Views: 3975
Reputation: 135
Remove the Formatting.Indented in your json call. That should fix it.
Upvotes: 1
Reputation: 140236
ResponseFormat = WebMessageFormat.Json
That will JSON encode the return value of the annotated method. If the return value is already a JSON string, then you are JSON encoding twice.. first the Road
object and then the JSON string resulting from the former.
So just return the Road
object and let the WebMessageFormat.json
handle the json encoding.
Upvotes: 2