本文整理汇总了C#中ObjectWriter.WriteValueAsBytes方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectWriter.WriteValueAsBytes方法的具体用法?C# ObjectWriter.WriteValueAsBytes怎么用?C# ObjectWriter.WriteValueAsBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectWriter
的用法示例。
在下文中一共展示了ObjectWriter.WriteValueAsBytes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestStringFragment
/// <exception cref="System.Exception"></exception>
public virtual void TestStringFragment()
{
string fragment = "01234567890";
ObjectWriter mapper = new ObjectWriter();
byte[] json = mapper.WriteValueAsBytes(fragment);
JsonDocument jsdoc = new JsonDocument(json);
NUnit.Framework.Assert.AreEqual(fragment, jsdoc.JsonObject());
}
示例2: TestJsonArray
/// <exception cref="System.Exception"></exception>
public virtual void TestJsonArray()
{
IList<object> array = new AList<object>();
array.AddItem("01234567890");
array.AddItem("bar");
array.AddItem(5);
array.AddItem(3.5);
array.AddItem(true);
array.AddItem(new DateTime().ToString());
ObjectWriter mapper = new ObjectWriter();
byte[] json = mapper.WriteValueAsBytes(array);
JsonDocument jsdoc = new JsonDocument(json);
NUnit.Framework.Assert.AreEqual(array, jsdoc.JsonObject());
}
示例3: TestJsonObject
/// <exception cref="System.Exception"></exception>
public virtual void TestJsonObject()
{
IDictionary<string, object> dict = new Dictionary<string, object>();
dict.Put("id", "01234567890");
dict.Put("foo", "bar");
dict.Put("int", 5);
dict.Put("double", 3.5);
dict.Put("bool", true);
dict.Put("date", new DateTime().ToString());
ObjectWriter mapper = new ObjectWriter();
byte[] json = mapper.WriteValueAsBytes(dict);
JsonDocument jsdoc = new JsonDocument(json);
NUnit.Framework.Assert.AreEqual(dict, jsdoc.JsonObject());
}
示例4: Encode
// create the same JSON encoding used by TouchDB
// this lets us test comparisons as they would be encoded
public virtual string Encode(object obj)
{
ObjectWriter mapper = new ObjectWriter();
try
{
byte[] bytes = mapper.WriteValueAsBytes(obj);
string result = Sharpen.Runtime.GetStringForBytes(bytes);
return result;
}
catch (Exception e)
{
Log.E(Tag, "Error encoding JSON", e);
return null;
}
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:17,代码来源:CollationTest.cs
示例5: TestIntegerFragment
/// <exception cref="System.Exception"></exception>
public virtual void TestIntegerFragment()
{
int fragment = 5;
ObjectWriter mapper = new ObjectWriter();
byte[] json = mapper.WriteValueAsBytes(fragment);
JsonDocument jsdoc = new JsonDocument(json);
NUnit.Framework.Assert.AreEqual(fragment, jsdoc.JsonObject());
}
示例6: TestDateFragment
/// <exception cref="System.Exception"></exception>
public virtual void TestDateFragment()
{
DateTime fragment = new DateTime();
ObjectWriter mapper = new ObjectWriter();
byte[] json = mapper.WriteValueAsBytes(fragment);
JsonDocument jsdoc = new JsonDocument(json);
NUnit.Framework.Assert.AreEqual(fragment, Sharpen.Extensions.CreateDate((long)jsdoc
.JsonObject()));
}