本文整理汇总了C#中Jayrock.Json.JsonTextWriter.WriteStartArray方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextWriter.WriteStartArray方法的具体用法?C# JsonTextWriter.WriteStartArray怎么用?C# JsonTextWriter.WriteStartArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jayrock.Json.JsonTextWriter
的用法示例。
在下文中一共展示了JsonTextWriter.WriteStartArray方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: JayrockWriterObjects
public static void JayrockWriterObjects ()
{
for (int j = 0; j < Common.Iterations; j++) {
StringBuilder output = new StringBuilder ();
JsonWriter writer = new JsonTextWriter (new StringWriter (output));
int n = Common.SampleObject.Length;
for (int i = 0; i < n; i += 2) {
switch ((char) Common.SampleObject[i]) {
case '{':
writer.WriteStartObject ();
break;
case '}':
writer.WriteEndObject ();
break;
case '[':
writer.WriteStartArray ();
break;
case ']':
writer.WriteEndArray ();
break;
case 'P':
writer.WriteMember (
(string) Common.SampleObject[i + 1]);
break;
case 'I':
writer.WriteNumber (
(int) Common.SampleObject[i + 1]);
break;
case 'D':
writer.WriteNumber (
(double) Common.SampleObject[i + 1]);
break;
case 'S':
writer.WriteString (
(string) Common.SampleObject[i + 1]);
break;
case 'B':
writer.WriteBoolean (
(bool) Common.SampleObject[i + 1]);
break;
case 'N':
writer.WriteNull ();
break;
}
}
}
}
示例2: Write
public static void Write(Coordinate coordinate, JsonTextWriter jwriter)
{
if (coordinate == null)
return;
if (jwriter == null)
throw new ArgumentNullException("jwriter", "A valid JSON writer object is required.");
jwriter.WriteStartArray();
jwriter.WriteNumber(coordinate.X);
jwriter.WriteNumber(coordinate.Y);
if (!double.IsNaN(coordinate.Z))
jwriter.WriteNumber(coordinate.Z);
jwriter.WriteEndArray();
}
示例3: JayrockWriterNumbers
public static void JayrockWriterNumbers ()
{
for (int i = 0; i < Common.Iterations; i++) {
StringBuilder output = new StringBuilder ();
JsonWriter writer = new JsonTextWriter (new StringWriter (output));
writer.WriteStartArray ();
foreach (int n in Common.SampleInts)
writer.WriteNumber (n);
foreach (double n in Common.SampleDoubles)
writer.WriteNumber (n);
writer.WriteEndArray ();
}
}
示例4: ToJSON
public void ToJSON(JsonTextWriter jwriter)
{
jwriter.WriteStartArray();
foreach (DictionaryEntry item in this.Dictionary)
{
jwriter.WriteStartObject();
jwriter.WriteMember("key");
jwriter.WriteString(item.Key.ToString());
//write the qualified type name of the value
//write the value
if (item.Value == null)
{
jwriter.WriteMember("type");
jwriter.WriteNull();
jwriter.WriteMember("value");
jwriter.WriteNull();
}
else
{
TypeConverter typeConverter = TypeDescriptor.GetConverter(item.Value.GetType());
jwriter.WriteMember("type");
jwriter.WriteString(item.Value.GetType().AssemblyQualifiedName);
jwriter.WriteMember("value");
jwriter.WriteString(typeConverter.ConvertToString(item.Value));
}
jwriter.WriteEndObject();
}
jwriter.WriteEndArray();
}
示例5: Request
public JsonTextWriter Request(string method, params string [] list)
{
JsonTextWriter writer = new JsonTextWriter();
writer.WriteStartObject ();
writer.WriteMember ("jsonrpc");
writer.WriteString ("2.0");
writer.WriteMember ("id");
writer.WriteString ("1");
writer.WriteMember ("method");
writer.WriteString (method);
writer.WriteMember ("params");
writer.WriteStartArray ();
foreach (string param in list)
writer.WriteString (param);
return writer;
}
示例6: Request
private JsonTextWriter Request(int id, string method, params string[] list)
{
JsonTextWriter writer = new JsonTextWriter();
string ID = id.ToString();
writer.WriteStartObject();
writer.WriteMember("jsonrpc");
writer.WriteString("2.0");
writer.WriteMember("id");
writer.WriteString(ID);
writer.WriteMember("method");
writer.WriteString(method);
writer.WriteMember("params");
writer.WriteStartArray();
foreach (string param in list)
writer.WriteString(param);
return writer;
}
示例7: GetWorkRpc
/// <summary>
/// Invokes the 'getwork' JSON method and parses the result into a new <see cref="T:Work"/> instance.
/// </summary>
/// <returns></returns>
public Work GetWorkRpc(IMiner miner, string comment)
{
var req = OpenRpc(miner, comment);
if (req == null)
return null;
// submit method invocation
using (var txt = new StreamWriter(req.GetRequestStream()))
using (var wrt = new JsonTextWriter(txt))
{
wrt.WriteStartObject();
wrt.WriteMember("id");
wrt.WriteString("json");
wrt.WriteMember("method");
wrt.WriteString("getwork");
wrt.WriteMember("params");
wrt.WriteStartArray();
wrt.WriteEndArray();
wrt.WriteEndObject();
wrt.Flush();
}
return ParseGetWork(req.GetResponse());
}
示例8: SubmitWorkRpc
/// <summary>
/// Invokes the 'getwork' JSON method, submitting the proposed work. Returns <c>true</c> if the service accepts
/// the proposed work.
/// </summary>
/// <param name="work"></param>
/// <returns></returns>
public bool SubmitWorkRpc(IMiner miner, Work work, string comment)
{
var req = OpenRpc(miner, comment);
if (req == null)
return false;
// header needs to have SHA-256 padding appended
var data = Sha256.AllocateInputBuffer(80);
// prepare header buffer with SHA-256
Sha256.Prepare(data, 80, 0);
Sha256.Prepare(data, 80, 1);
// dump header data on top of padding
Array.Copy(work.Header, data, 80);
// encode in proper format
var solution = Memory.Encode(data);
Console.WriteLine();
Console.WriteLine("SOLUTION: {0,10} {1}", miner.GetType().Name, Memory.Encode(work.Header));
Console.WriteLine();
Console.WriteLine();
using (var txt = new StreamWriter(req.GetRequestStream()))
using (var wrt = new JsonTextWriter(txt))
{
wrt.WriteStartObject();
wrt.WriteMember("id");
wrt.WriteString("json");
wrt.WriteMember("method");
wrt.WriteString("getwork");
wrt.WriteMember("params");
wrt.WriteStartArray();
wrt.WriteString(solution);
wrt.WriteEndArray();
wrt.WriteEndObject();
wrt.Flush();
}
using (var txt = new StreamReader(req.GetResponse().GetResponseStream()))
using (var rdr = new JsonTextReader(txt))
{
if (!rdr.MoveToContent() && rdr.Read())
throw new JsonException("Unexpected content from 'getwork <data>'.");
var response = JsonConvert.Import<JsonSubmitWork>(rdr);
if (response == null)
throw new JsonException("No response returned.");
if (response.Error != null)
Console.WriteLine("JSON-RPC: {0}", response.Error);
Console.WriteLine();
Console.WriteLine("{0}: {1,10} {2}", response.Result ? "ACCEPTED" : "REJECTED", miner.GetType().Name, Memory.Encode(work.Header));
Console.WriteLine();
Console.WriteLine();
return response.Result;
}
}
示例9: WriteCategories
private static void WriteCategories(IEnumerable<ICategory> categories, TextWriter writer)
{
using (var jsonWriter = new JsonTextWriter(writer))
{
jsonWriter.WriteStartArray();
foreach (var category in categories)
{
jsonWriter.WriteStartObject();
jsonWriter.WriteMember("id");
jsonWriter.WriteString(category.Id.ToString());
jsonWriter.WriteMember("name");
jsonWriter.WriteString(category.Name);
jsonWriter.WriteMember("value");
jsonWriter.WriteString(category.Name);
jsonWriter.WriteEndObject();
}
jsonWriter.WriteEndArray();
}
}
示例10: save_index
private static void save_index()
{
lock (l)
{
using (TextWriter tw = File.CreateText(FileIndexSaveFile))
{
using (JsonTextWriter jw = new JsonTextWriter(tw))
{
jw.PrettyPrint = false;
jw.WriteStartArray();
foreach (var kvp in file_index)
{
jw.WriteStartObject();
jw.WriteMember(FILE_HASH);
jw.WriteString(kvp.Key);
jw.WriteMember(DATA);
jw.WriteStartArray();
foreach (var i in kvp.Value.GetRepostsData())
{
jw.WriteStartObject();
jw.WriteMember(BOARD);
jw.WriteString(i.Board);
jw.WriteMember(FILE_NAME);
jw.WriteString(i.FileName);
jw.WriteMember(THREAD_ID);
jw.WriteNumber(i.ThreadID);
jw.WriteMember(POST_ID);
jw.WriteNumber(i.PostID);
jw.WriteEndObject();
}
jw.WriteEndArray();
jw.WriteEndObject();
}
jw.WriteEndArray();
}
}
}
need_save = false;
}
示例11: SubscribeDailyGroupStatistics
public int SubscribeDailyGroupStatistics()
{
int nReqID = GetUniqueReqID();
foreach (int groupId in m_groupIds)
{
Jayrock.Json.JsonTextWriter jsonWriter = new Jayrock.Json.JsonTextWriter();
jsonWriter.WriteStartObject();
jsonWriter.WriteMember("version");
jsonWriter.WriteNumber(1);
jsonWriter.WriteMember("topic");
jsonWriter.WriteString("contact-center");
jsonWriter.WriteMember("request-id");
jsonWriter.WriteNumber(nReqID);
jsonWriter.WriteMember("message");
jsonWriter.WriteString("subscribe-events");
jsonWriter.WriteMember("subscribe");
jsonWriter.WriteStartArray();
jsonWriter.WriteStartArray();
jsonWriter.WriteString("ecc");
jsonWriter.WriteString("daily-group-stats");
jsonWriter.WriteStartArray();
jsonWriter.WriteString(groupId.ToString());
jsonWriter.WriteEndArray();
jsonWriter.WriteEndArray();
jsonWriter.WriteEndArray();
jsonWriter.WriteEndObject();
if (!SendRequest(jsonWriter.ToString()))
return -1;
}
return nReqID;
}
示例12: JayrockOutputFile
public static void JayrockOutputFile ()
{
using (FileStream fs = new FileStream ("jayrock_out.txt",
FileMode.Create)) {
StreamWriter out_stream = new StreamWriter (fs);
StringReader sr = new StringReader (Common.JsonText);
JsonReader reader = new JsonTextReader (sr);
out_stream.WriteLine (
"*** Reading with Jayrock.Json.JsonReader");
while (reader.Read ()) {
out_stream.Write ("Token: {0}", reader.TokenClass);
if (reader.Text != null)
out_stream.WriteLine (" Value: {0}", reader.Text);
else
out_stream.WriteLine ("");
}
out_stream.WriteLine (
"\n*** Writing with Jayrock.Json.JsonWriter");
JsonWriter writer = new JsonTextWriter (out_stream);
int n = Common.SampleObject.Length;
for (int i = 0; i < n; i += 2) {
switch ((char) Common.SampleObject[i]) {
case '{':
writer.WriteStartObject ();
break;
case '}':
writer.WriteEndObject ();
break;
case '[':
writer.WriteStartArray ();
break;
case ']':
writer.WriteEndArray ();
break;
case 'P':
writer.WriteMember (
(string) Common.SampleObject[i + 1]);
break;
case 'I':
writer.WriteNumber (
(int) Common.SampleObject[i + 1]);
break;
case 'D':
writer.WriteNumber (
(double) Common.SampleObject[i + 1]);
break;
case 'S':
writer.WriteString (
(string) Common.SampleObject[i + 1]);
break;
case 'B':
writer.WriteBoolean (
(bool) Common.SampleObject[i + 1]);
break;
case 'N':
writer.WriteNull ();
break;
}
}
out_stream.WriteLine (
"\n\n*** Data imported with " +
"Jayrock.Json.Conversion.JsonConvert\n");
Person art = (Person) JsonConvert.Import (typeof (Person),
Common.PersonJson);
out_stream.Write (art.ToString ());
out_stream.WriteLine (
"\n\n*** Object exported with " +
"Jayrock.Json.Conversion.JsonConvert\n");
out_stream.Write (JsonConvert.ExportToString (
Common.SamplePerson));
out_stream.WriteLine (
"\n\n*** Generic object exported with " +
"Jayrock.Json.Conversion.JsonConvert\n");
//.........这里部分代码省略.........