c# - My .NET web service method needs to return a JSON result to the calling client (an iOS device), but is returning a bunch of \r\n's -
presently, i'm returning string
out of web method call, ios device gets. when ios gets data, string representation of json object, contains bunch of \n\r
characters number of backslashes (\
) - result, ios device doesn't recognize valid json. see below:
"{\r\n \"bytedata\": \"uesdbaoaaaaaallp...etc."
i not sure if it's because of flawed code below- there see i'm doing wrong below? using json.net.
[httpget] public string gettpkmap(string filename) { // go out file share map string sharepath = string.format(@"\\server\shared\tpk\{0}", filename + ".tpk"); filestream fs = file.open(sharepath, filemode.open, fileaccess.read); // load filestream byte array int length = (int)fs.length; byte[] data = new byte[length]; fs.read(data, 0, length); fs.close(); // convert bytedata base64string pass client string strdata = convert.tobase64string(data); dynamic tpkbytedata = new jobject(); tpkbytedata.bytedata = strdata; jobject val = (jobject)jtoken.fromobject(tpkbytedata); return val.tostring(); }
you should use overload of tostring()
takes formatting parameter:
return val.tostring(formatting.none, yourjsonformatters);
Comments
Post a Comment