Bug 5920 - JsonObject.ToString() not escaping new lines.
Summary: JsonObject.ToString() not escaping new lines.
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.2.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-06-29 03:55 UTC by Terry
Modified: 2013-05-21 13:03 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NOT_REPRODUCIBLE

Description Terry 2012-06-29 03:55:54 UTC
I have a class that overrides ToString() to convert the class to a string. Ie:

public override string ToString()
{
     if( Id == -1 )
           return "";
     else
          return Name + "\n" + Unit
                   + "\n" + AddressLine1 + "\n" + AddressLine2 + "\n" + AddressLine3 + "\n" + AddressLine4
                   + "\n" + City + "\n" + State + "\n" + PostCode + "\n" + Country;
}

I then I add the string to a JsonObject .

JsonObject JObject = new JsonObject();
                JObject.Add( "Address", TheClass.ToString() );

I then generate the Json string using JsonObject.ToString(). Ie:

string JsonString = JObject.ToString();

When the string is generated the new lines are just passed straight through without being escaped, causing the receiving end to generate an error.

I thought that it was meant to escape all funny characters like \r \n \b \t.
Comment 1 Peter Collins 2013-05-21 13:03:36 UTC
Using the reproduction case above, I am not able to reproduce the error. Printing JObject.ToString(); to the console properly displays the values I entered with escaped new lines, as seen below.

{"Address": "Peter
35
ADD1
ADD2
ADD3
ADD4
Cambridge
MA
02138
USA"}

Please reopen if you are still encountering this issue.

Tested against XA 4.6.6 (6d7480e9)