public void WriteJsonUtf8() { var buffer = new byte[1024]; var stream = new MemoryStream(buffer); var json = new JsonWriter(stream, FormattingData.Encoding.Utf8, prettyPrint:true); Write(json); var str = Encoding.UTF8.GetString(buffer, 0, (int)stream.Position); Console.WriteLine(str); Assert.Equal(expected, str.Replace("\n", "").Replace(" ","")); }
static void Write(JsonWriter json) { json.WriteObjectStart(); json.WriteAttribute("age", 30); json.WriteAttribute("first", "John"); json.WriteAttribute("last", "Smith"); json.WriteMember("phoneNumbers"); json.WriteArrayStart(); json.WriteString("425-000-1212"); json.WriteString("425-000-1213"); json.WriteArrayEnd(); json.WriteMember("address"); json.WriteObjectStart(); json.WriteAttribute("street", "1 Microsoft Way"); json.WriteAttribute("city", "Redmond"); json.WriteAttribute("zip", 98052); json.WriteObjectEnd(); json.WriteObjectEnd(); }
public void WriteJsonUtf16() { var buffer = new byte[1024]; var stream = new MemoryStream(buffer); var json = new JsonWriter(stream, FormattingData.Encoding.Utf16); Write(json); var written = buffer.Slice(0, (int)stream.Position); var str = written.CreateString(); Assert.Equal(expected, str.Replace(" ", "")); }