Reputation: 3595
I have a ASP.NET Web API REST service running on a server that feeds data back and forth to my Android Apps. I use a lot of Newtonsoft Json with great success but it is causing me a problem on a new method I am writing.
In a nutshell I am reading a large String from my SQL Server DB, putting it into a simple object, serializing it out in a Json string, and posting an HTTP POST response. What is happening is that the serializeObject is inserting newline characters (/n) once every 76 characters into the string.
the following code...
Logger.log("retPair.publicKey = " + retPair.publicKey);
returnString = JsonConvert.SerializeObject(retPair);
Logger.log("Verify Talker return is " + returnString);
Produces the following two log entries . . .
10/18/2015 3:19:36 PMDBAWP7 retPair.publicKey = MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzQn5Lw2PTlVkSOjg7ycZMVDUmaGYQhVe I82XcheaPDyr16tCp4P2oJCjKlKPeN1v5qN4kR4BKo3xjUwM+BWO6i3mr10C9/mbXUoInVXVODRu lkdIXFPthSkBMytl5jAjaf1Ep4F3Y64WVwYXd9ASYpfNN5FMvxUzYbdkV7QNObsfHkAnr98uamFg SJ0dGJ8svQ1DKiKz4db+zkzalXNHqh7mbV7kxRkT08GlocFEOp/xaLISlrH03CcKozerTbY/NkMx XE7s7+wAuREgjKdNkpjRYUTMdm/QhxcvJf8UU7tE89POHkZ1wghPpAFIJ6kdCVBewrfaJVdcwJk8 WdzzaQIDAQAB
10/18/2015 3:19:36 PMDBAWP7 Verify Talker return is {"phoneKey":"cathyblakely","publicKey":"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzQn5Lw2PTlVkSOjg7ycZMVDUmaGYQhVe\nI82XcheaPDyr16tCp4P2oJCjKlKPeN1v5qN4kR4BKo3xjUwM+BWO6i3mr10C9/mbXUoInVXVODRu\nlkdIXFPthSkBMytl5jAjaf1Ep4F3Y64WVwYXd9ASYpfNN5FMvxUzYbdkV7QNObsfHkAnr98uamFg\nSJ0dGJ8svQ1DKiKz4db+zkzalXNHqh7mbV7kxRkT08GlocFEOp/xaLISlrH03CcKozerTbY/NkMx\nXE7s7+wAuREgjKdNkpjRYUTMdm/QhxcvJf8UU7tE89POHkZ1wghPpAFIJ6kdCVBewrfaJVdcwJk8\nWdzzaQIDAQAB\n"}
BTW, the data is a Public encryption key.
As you can see the second log entry has /n every 76 characters. Researching this problem on the web I see other people have gotten this problem but no one has received a response that eliminated the problem. Formatting.NONE has not effect.
The product version of my Newtonsoft.Json.dll is 4.5.6.14930. Anyone know why this might be happenning. I know I can eliminate the \n in the string but that is my last resort. Thanks, Dean
Upvotes: 1
Views: 15202
Reputation: 241890
As seen in the JSON spec on www.json.org, newlines in a string are encoded as \n
when in JSON.
JSON.Net is not introducing newline characters into the output arbitrarily, but rather your original string already has newline characters, so they have to be encoded.
Upvotes: 1