public void SerializeJavaScriptDate1970() { using (writerNoIndent.WriteArray()) { writerNoIndent.WriteValue(new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), JSonWriterDateFormat.JavaScript); } Assert.AreEqual("[\"\\/Date(0)\\/\"]", writerNoIndent.ToString()); }
public void TestSerializeArrayWithString() { string text = "Jakiś tekst!\r\n Paweł"; writer.WriteArrayBegin(); writer.WriteValue(text); writer.WriteArrayEnd(); Assert.AreEqual(writer.ToString(), "[\r\n \"Jakiś tekst!\\r\\n Paweł\"\r\n]", "Text is deserialized incorrectly!"); var reader = new JSonReader(writer.ToString()); var result = reader.Read() as object[]; Assert.AreEqual(text, result[0], "Text after deserialization are not equal!"); }
public async Task <IJSonObject> CheckRayzReplies(string rayzid, IEnumerable <string> rayzsList) { try { var writer = new JSonWriter(true); var reader = new JSonReader(); writer.WriteObjectBegin(); writer.WriteMember("userId", _deviceId); writer.WriteMember("rayzId", rayzid); writer.WriteMember("rayzReplyIds"); writer.WriteArrayBegin(); //Group up the records in the collection foreach (var record in rayzsList) { writer.WriteValue(record); } writer.WriteArrayEnd(); writer.WriteObjectEnd(); var json = new StringContent(writer.ToString()); json.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); var response = await _client.PostAsync(new Uri(ServerBaseUri, "/rayz/reply/check"), json); var cr = CheckResponse(response); if (cr != null) { var creply = reader.ReadAsJSonObject(cr); return(creply); } var r = await response.Content.ReadAsStringAsync(); var reply = reader.ReadAsJSonObject(r); return(reply); } catch (Exception) { return(null); } }
public void WriteEmbeddedObject() { writer.WriteArrayBegin(); writer.WriteObjectBegin(); writer.WriteMember("Name", "Paweł"); writer.WriteMember("Salary", 100); writer.WriteMember("Company"); writer.WriteObjectBegin(); writer.WriteMember("Name", "CodeTitans"); writer.WriteMember("Address", "ABCD"); writer.WriteMember("Value", 10.28437411e2); writer.WriteMember("Started", DateTime.Now); writer.WriteMemberNull("Account"); writer.WriteObjectEnd(); writer.WriteObjectEnd(); writer.WriteObjectBegin(); writer.WriteMember("Name", "Aga"); writer.WriteMember("Salary", 200); writer.WriteObjectEnd(); writer.WriteValue(101); writer.WriteValue("New Item"); writer.WriteArrayEnd(); }