I'm using Newtonsoft.Json to parse object to json string. It returns somethink like this:
{\"code\":-1,\"idName\":\"empty\",\"idValue\":0,\"message\":\"Failed,can not read object from body\"}
it is not a valid json string i think, anyone can work me out?
What I want is something like this:
{"code":-1,"idName":"empty\",\"idValue\":0,\"message\":\"Failed,can not read object from body\"}
public static class CommonUtility
{
// format response string
public static string FormatResponseString(int code, string idName, long idValue, string message)
{
ResponseString rs = new ResponseString();
rs.code = code;
rs.idName = idName;
rs.idValue = idValue;
rs.message = message;
string json = JsonConvert.SerializeObject(rs);
return json;
}
}
public class ResponseString
{
public int code;
public string idName;
public long idValue;
public string message;
}
EDIT: this is actual json from the response fidder TextView I can see:
"{\"code\":-1,\"idName\":\"empty\",\"idValue\":0,\"message\":\"Failed,can not read object from body\"}"
the scenario is this: I put the serialized json string in web api CreateResponse method. I can see the response string in fidder like I said in the question which is not valid json
Request.CreateResponse(HttpStatusCode.Created, returnString);
returnString is json string from the serialized ResponseString object
I donot think it is a valid string , am I wrong?

