Skip to content

Commit c10d076

Browse files
committed
Implement text output example in C#.
1 parent 6c6bb3a commit c10d076

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/c/obj/
22
/c/*.exe
3+
/cs/*.exe

cs/build.cmd

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
call "%VS100COMNTOOLS%vsvars32.bat"
3+
csc cat.cs

cs/cat-run.cmd

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.\cat.exe < ..\Test.json

cs/cat.cs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Web.Script.Serialization;
5+
6+
namespace Cat
7+
{
8+
class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
StreamReader sr = new StreamReader(Console.OpenStandardInput());
13+
string input = sr.ReadToEnd();
14+
sr.Dispose();
15+
16+
JavaScriptSerializer ser = new JavaScriptSerializer();
17+
dynamic json = ser.DeserializeObject(input);
18+
for (int i = 1; i < json.Length; i++)
19+
{
20+
dynamic block = json[i];
21+
string blockType = block[0];
22+
Dictionary<string, object> blockAttr = block[1];
23+
24+
for (int j = 2; j < block.Length; j++)
25+
{
26+
dynamic span = block[j];
27+
string spanType = span[0];
28+
string text = span[1];
29+
Console.Write(text);
30+
}
31+
32+
Console.WriteLine();
33+
Console.WriteLine();
34+
}
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)