本文整理汇总了C#中LitJson.JsonWriter.WritePropertyName方法的典型用法代码示例。如果您正苦于以下问题:C# JsonWriter.WritePropertyName方法的具体用法?C# JsonWriter.WritePropertyName怎么用?C# JsonWriter.WritePropertyName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LitJson.JsonWriter
的用法示例。
在下文中一共展示了JsonWriter.WritePropertyName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: generateReadParamJson
public static string generateReadParamJson()
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
JsonWriter writer = new JsonWriter(sb);
writer.WriteObjectStart();
writer.WritePropertyName("action");
writer.Write("get");
writer.WritePropertyName("id");
writer.Write("SC9008637");
writer.WritePropertyName("page");
writer.Write("channel_param");
writer.WriteObjectEnd();
return sb.ToString();
}
示例2: ListStepDefinitionsAsJson
public string ListStepDefinitionsAsJson()
{
StringBuilder sb = new StringBuilder();
JsonWriter writer = new JsonWriter(sb);
writer.WriteArrayStart();
foreach (StepDefinition sd in _stepDefinitions)
{
writer.WriteObjectStart();
writer.WritePropertyName("id");
writer.Write(sd.Id);
writer.WritePropertyName("regexp");
writer.Write(sd.Pattern);
writer.WriteObjectEnd();
}
writer.WriteArrayEnd();
return sb.ToString();
}
示例3: LitJsonWriterObjects
public static void LitJsonWriterObjects ()
{
for (int j = 0; j < Common.Iterations; j++) {
StringBuilder output = new StringBuilder ();
JsonWriter writer = new JsonWriter (new StringWriter (output));
int n = Common.SampleObject.Length;
for (int i = 0; i < n; i += 2) {
switch ((char) Common.SampleObject[i]) {
case '{':
writer.WriteObjectStart ();
break;
case '}':
writer.WriteObjectEnd ();
break;
case '[':
writer.WriteArrayStart ();
break;
case ']':
writer.WriteArrayEnd ();
break;
case 'P':
writer.WritePropertyName (
(string) Common.SampleObject[i + 1]);
break;
case 'I':
writer.Write (
(int) Common.SampleObject[i + 1]);
break;
case 'D':
writer.Write (
(double) Common.SampleObject[i + 1]);
break;
case 'S':
writer.Write (
(string) Common.SampleObject[i + 1]);
break;
case 'B':
writer.Write (
(bool) Common.SampleObject[i + 1]);
break;
case 'N':
writer.Write (null);
break;
}
}
}
}
示例4: ErrorObjectClosingTest
public void ErrorObjectClosingTest()
{
JsonWriter writer = new JsonWriter ();
writer.WriteObjectStart ();
writer.WritePropertyName ("foo");
writer.Write ("bar");
writer.WriteArrayEnd ();
}
示例5: ObjectTest
public void ObjectTest()
{
JsonWriter writer = new JsonWriter ();
string json = "{\"flavour\":\"strawberry\",\"color\":\"red\"," +
"\"amount\":3}";
writer.WriteObjectStart ();
writer.WritePropertyName ("flavour");
writer.Write ("strawberry");
writer.WritePropertyName ("color");
writer.Write ("red");
writer.WritePropertyName ("amount");
writer.Write (3);
writer.WriteObjectEnd ();
Assert.AreEqual (writer.ToString (), json);
}
示例6: NestedObjectsTest
public void NestedObjectsTest()
{
JsonWriter writer = new JsonWriter ();
string json = "{\"book\":{\"title\":" +
"\"Structure and Interpretation of Computer Programs\"," +
"\"details\":{\"pages\":657}}}";
writer.WriteObjectStart ();
writer.WritePropertyName ("book");
writer.WriteObjectStart ();
writer.WritePropertyName ("title");
writer.Write (
"Structure and Interpretation of Computer Programs");
writer.WritePropertyName ("details");
writer.WriteObjectStart ();
writer.WritePropertyName ("pages");
writer.Write (657);
writer.WriteObjectEnd ();
writer.WriteObjectEnd ();
writer.WriteObjectEnd ();
Assert.AreEqual (writer.ToString (), json);
}
示例7: Serialize
private void Serialize(Message message, JsonWriter writer, bool inStream)
{
if (!inStream) {
writer.WriteObjectStart();
writer.WritePropertyName("jsonrpc");
writer.Write("1.0");
}
if (message.Attributes.Contains("id")) {
writer.WritePropertyName("id");
// TODO: we presume is a number castable to int4 ...
writer.Write((int)message.Attributes["id"]);
}
if (message is MessageStream) {
writer.WritePropertyName("stream");
writer.WriteArrayStart();
foreach (Message m in ((MessageStream)message)) {
Serialize(m, writer, true);
}
writer.WriteArrayEnd();
} else if (message.MessageType == MessageType.Request) {
writer.WritePropertyName("method");
writer.Write(message.Name);
writer.WritePropertyName("params");
writer.WriteArrayStart();
foreach (MessageArgument argument in message.Arguments) {
WriteValue(argument, writer);
}
writer.WriteArrayEnd();
} else {
writer.WritePropertyName("result");
IList<MessageArgument> args = message.Arguments;
if (args.Count == 0) {
writer.Write(null);
} else if (args.Count == 1) {
if (message.HasError) {
writer.Write(null);
writer.WritePropertyName("error");
writer.WriteObjectStart();
writer.WritePropertyName("message");
writer.Write(message.ErrorMessage);
writer.WritePropertyName("source");
writer.Write(message.Error.Source);
writer.WritePropertyName("stackTrace");
//TODO: does the string needs to be normalized?
writer.Write(message.ErrorStackTrace);
writer.WriteObjectEnd();
} else {
WriteValue(args[0], writer);
writer.WritePropertyName("error");
writer.Write(null);
}
} else {
// here we are sure we don't have an error, so skip
// any check about it
writer.WriteArrayStart();
foreach (MessageArgument argument in message.Arguments) {
WriteValue(argument, writer);
}
writer.WriteArrayEnd();
}
}
if (!inStream)
writer.WriteObjectEnd();
}
示例8: WriteResponse
public void WriteResponse(string id, Response resp, Exception error, StreamWriter sw)
{
JsonWriter writer = new JsonWriter(sw);
writer.WriteObjectStart();
writer.WritePropertyName("id");
writer.Write(id);
if (error == null)
{
writer.WritePropertyName("error");
writer.Write(null);
writer.WritePropertyName("result");
if (resp == null)
writer.Write(null);
else
resp.Write(writer, false);
}
else
{
writer.WritePropertyName("result");
writer.Write(null);
writer.WritePropertyName("error");
writer.Write(string.Format("{0}\n{1}", error.Message, error.StackTrace.ToString()));
}
writer.WriteObjectEnd();
}
示例9: GetSchedule
public static string GetSchedule(IDbConnection db)
{
TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1);
long today = (long)t.TotalSeconds;
StringBuilder sb = new StringBuilder();
LitJson.JsonWriter writer = new LitJson.JsonWriter(sb);
writer.WriteObjectStart();
writer.WritePropertyName("bookings");
writer.WriteArrayStart();
using (IDbCommand command = db.CreateCommand())
{
command.CommandText = "select id, day, [from], till, _user, _meetingroom, users_notified, users_to_be_notified, users_checkedin from booking where day>= @Day order by day, [from]";
IDbDataParameter p = command.CreateParameter();
p.ParameterName = "@Day";
p.Value = today;
command.Parameters.Add(p);
using (IDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
new MeetingRoomBooking(reader).Write(writer);
}
}
}
writer.WriteArrayEnd();
writer.WritePropertyName("rooms");
writer.WriteObjectStart();
List<MeetingRoom> MeetingRooms = new List<MeetingRoom>();
MeetingRooms = MeetingRoom.List(db);
foreach (MeetingRoom meetingRoom in MeetingRooms)
{
writer.WritePropertyName(meetingRoom.Id.ToString());
meetingRoom.Write(writer);
}
writer.WriteObjectEnd();
writer.WritePropertyName("users");
writer.WriteObjectStart();
List<User> Users = new List<User>();
Users = User.list(db);
foreach (User user in Users)
{
writer.WritePropertyName(user.Email);
user.Write(writer);
}
writer.WriteObjectEnd();
writer.WriteObjectEnd();
return sb.ToString();
}
示例10: CreateStomt
public void CreateStomt(bool negative, string target, string text)
{
StringBuilder json = new StringBuilder();
LitJson.JsonWriter writer = new LitJson.JsonWriter(json);
writer.WriteObjectStart();
writer.WritePropertyName("anonym");
writer.Write(true);
writer.WritePropertyName("negative");
writer.Write(negative);
writer.WritePropertyName("target_id");
writer.Write(target);
writer.WritePropertyName("text");
writer.Write(text);
writer.WriteObjectEnd();
StartCoroutine(CreateStomtAsync(json.ToString()));
}
示例11: ErrorValueExpectedTest
public void ErrorValueExpectedTest()
{
JsonWriter writer = new JsonWriter ();
writer.WriteObjectStart ();
writer.WritePropertyName ("foo");
writer.WriteObjectEnd ();
}
示例12: ToJson
public string ToJson()
{
var jsWriter = new JsonWriter();
jsWriter.WriteObjectStart();
jsWriter.WritePropertyName("alg");
jsWriter.Write(Algorithm.ToString());
if (null != KeyUri)
{
switch (KeyFormat)
{
case KeyFormat.Json:
jsWriter.WritePropertyName("jku");
break;
case KeyFormat.X509:
jsWriter.WritePropertyName("xku");
break;
case KeyFormat.Rfc4050:
jsWriter.WritePropertyName("xdu");
break;
}
jsWriter.Write(KeyUri.ToString());
}
if (false == string.IsNullOrEmpty(KeyId))
{
jsWriter.WritePropertyName("kid");
jsWriter.Write(KeyId);
}
jsWriter.WriteObjectEnd();
return jsWriter.ToString();
}
示例13: WriteValue
public void WriteValue(JsonWriter writer, string typeName, object value, string format)
{
writer.WriteObjectStart();
writer.WritePropertyName("$type");
writer.Write(typeName);
if (typeName == "dateTime") {
if (String.IsNullOrEmpty(format))
format = DateTimeIso8601Format;
writer.WritePropertyName("format");
writer.Write(format);
writer.WritePropertyName("value");
writer.Write(((DateTime)value).ToString(format));
} else if (typeName == "dataAddress") {
DataAddress dataAddress = (DataAddress)value;
writer.WritePropertyName("block-id");
writer.Write(dataAddress.BlockId);
writer.WritePropertyName("data-id");
writer.Write(dataAddress.DataId);
} else if (typeName == "serviceAddress") {
IServiceAddress serviceAddress = (IServiceAddress)value;
writer.WritePropertyName("address");
writer.Write(serviceAddress.ToString());
} else if (typeName == "singleNodeSet" ||
typeName == "compressedNodeSet") {
NodeSet nodeSet = (NodeSet)value;
writer.WritePropertyName("nids");
writer.WriteArrayStart();
for (int i = 0; i < nodeSet.NodeIds.Length; i++) {
writer.Write(nodeSet.NodeIds[i]);
}
writer.WriteArrayEnd();
writer.WritePropertyName("data");
string base64Data = Convert.ToBase64String(nodeSet.Buffer);
writer.Write(base64Data);
} else {
throw new FormatException();
}
writer.WriteObjectEnd();
}
示例14: UpdateIssue
public void UpdateIssue(IssueUpdate update, NetworkCredential credential,
Action<string> stdout, Action<string> stderr)
{
var client = new WebClient();
client.Headers.Add("Content-Type", "application/json");
client.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(credential.UserName + ":" + credential.Password)));
var jsonRPCQuery = new JsonWriter();
jsonRPCQuery.WriteObjectStart();
jsonRPCQuery.WritePropertyName("method");
jsonRPCQuery.Write("ticket.update");
jsonRPCQuery.WritePropertyName("params");
jsonRPCQuery.WriteArrayStart();
jsonRPCQuery.Write(update.Issue.Id);
jsonRPCQuery.Write(update.Comment);
jsonRPCQuery.WriteObjectStart();
jsonRPCQuery.WritePropertyName("action");
jsonRPCQuery.Write("resolve");
jsonRPCQuery.WritePropertyName("action_resolve_resolve_resolution");
jsonRPCQuery.Write("fixed");
jsonRPCQuery.WriteObjectEnd();
jsonRPCQuery.Write(true);
jsonRPCQuery.WriteArrayEnd();
jsonRPCQuery.WriteObjectEnd();
client.UploadString(this.RPCUrl(), jsonRPCQuery.ToString());
}
示例15: DownloadIssues
public Action DownloadIssues(string project, int start, bool includeClosedIssues,
Func<IEnumerable<Issue>, bool> onData,
Action<DownloadProgressChangedEventArgs> onProgress,
Action<bool, Exception> onCompleted)
{
Debug.Assert(project != null);
Debug.Assert(onData != null);
var client = new WebClient();
client.Headers.Add("Content-Type", "application/json");
client.UploadStringCompleted += (sender, args) =>
{
if (args.Cancelled || args.Error != null)
{
if (onCompleted != null)
onCompleted(args.Cancelled, args.Error);
return;
}
JsonData data = JsonMapper.ToObject(args.Result);
if (data["error"] != null)
{
if (onCompleted != null)
onCompleted(false, new Exception((string)data["error"]["message"]));
return;
}
else if (data["result"] != null && data["result"].Count > 0)
{
var client2 = new WebClient();
client2.Headers.Add("Content-Type", "application/json");
var jsonRPCQuery = new JsonWriter();
jsonRPCQuery.WriteObjectStart();
jsonRPCQuery.WritePropertyName("method");
jsonRPCQuery.Write("system.multicall");
jsonRPCQuery.WritePropertyName("params");
jsonRPCQuery.WriteArrayStart();
for (int i = 0; i < data["result"].Count - 1; i++)
{
jsonRPCQuery.WriteObjectStart();
jsonRPCQuery.WritePropertyName("method");
jsonRPCQuery.Write("ticket.get");
jsonRPCQuery.WritePropertyName("params");
jsonRPCQuery.WriteArrayStart();
jsonRPCQuery.Write((int)data["result"][i]);
jsonRPCQuery.WriteArrayEnd();
jsonRPCQuery.WriteObjectEnd();
}
client2.UploadStringCompleted += (sender2, args2) =>
{
if (args2.Cancelled || args2.Error != null)
{
return;
}
int lastObjectStart = 0;
int count = 0;
bool inQuote = false;
bool lastWasBackslash = false;
for (int n = 1; n < args2.Result.Length; n++)
{
if (inQuote)
{
if (args2.Result[n] == '"' && !lastWasBackslash)
{
inQuote = false;
}
else if (args2.Result[n] == '\\')
{
lastWasBackslash = !lastWasBackslash;
}
else
{
lastWasBackslash = false;
}
}
else
{
if (args2.Result[n] == '"')
{
inQuote = true;
}
else if (args2.Result[n] == '}')
{
--count;
if (count == 0)
{
n++;
JsonData issueData = JsonMapper.ToObject(args2.Result.Substring(lastObjectStart, n - lastObjectStart));
TracIssue[] issues = new TracIssue[1];
issues[0] = new TracIssue();
issues[0].Id = (int)issueData["result"][0];
if (issueData["result"][3].ToString().Contains("milestone"))
{
issues[0].Milestone = (string)issueData["result"][3]["milestone"];
}
issues[0].Owner = (string)issueData["result"][3]["owner"];
//.........这里部分代码省略.........