mono/mono — pull request #1155 by steffen-kiess (2014-07-11 14:22:17+00:00)
Title: Fix System.Json string handling and make order of JsonObject entries deterministic

Fix handling of strings in System.Json:
- Escape control characters, as required by JSON spec (i.e. ASCII 0-31)
- Escape invalid surrogate pairs (so we get valid Unicode even for invalid strings)
- Escape characters invalid in JavaScript strings (not needed to get valid JSON, get generally useful)
- Escape "</" for HTML script tags (not needed to get valid JSON, get generally useful as "</" is not a valid sequence in HTML <script> tags)
- Fix serialization of chars
- Remove unused variable in JavaScriptReader.cs
- Add tests

Use SortedDictionary in System.Json.JsonObject:
Currently JsonObject uses a Dictionary and JsonValue does not sort the keys in SaveInternal(). As iterating over a Dictionary returns the values in random order, this causes the JSON string to be non-deterministic.
Switching to SortedDictionary makes sure that the same object always will produce the same JSON string.
The keys are sorted using StringComparer.Ordinal to produce the same order in all locales.