I'm trying to serialize a list of objects into json, but in the json all of the data members are surrounded by "\". For example, my object is:
public class ResObject
{
public double productPrice { get; set; }
public string productName { get; set; }
public double distance { get; set; }
public string fullAddress { get; set; }
public string fullStoreName { get; set; }
public string promotion { get; set; }
}
and the resulted json is:
"[{\"productPrice\":4,\"productName\":\"Milk\",\"distance\":0,\"fullAddress\":\"UK\",\"fullStoreName\":\"LiaStore\",\"promotion\":null},...]"
I used this codes:
string json = JsonConvert.SerializeObject(Products, Formatting.None);
OR
var json = new JavaScriptSerializer().Serialize(Products);
OR
//Create a stream to serialize the object to.
MemoryStream ms = new MemoryStream();
// Serializer the User object to the stream.
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(List<ResObject>));
ser.WriteObject(ms, Products);
byte[] json = ms.ToArray();
ms.Close();
return Encoding.UTF8.GetString(json, 0, json.Length);
but it did not helped :(
(Products is List<ResObject> Products
)
Thank you!
EDIT: I fixed it, the problem was that I serialized list and returned it and since it is WebAPI it was the problem. The fix was to return the list and delete the serialize.