/// <summary> /// Converts <see cref="BayeuxRequest"/> to string containing its JSON representation. /// </summary> protected string SerializeRequest(BayeuxRequest request) { _writerCache.Remove(0, _writerCache.Length); _jsonWriter.WriteArrayBegin(); request.Write(_jsonWriter); _jsonWriter.WriteArrayEnd(); return(_jsonWriter.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 WriteAnArray() { writer.WriteArrayBegin(); writer.WriteArrayEnd(); Assert.AreEqual("[]", writer.ToString(), "Empty array expected!"); }