本文整理汇总了C#中JsonTextWriter.WriteEndObject方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextWriter.WriteEndObject方法的具体用法?C# JsonTextWriter.WriteEndObject怎么用?C# JsonTextWriter.WriteEndObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonTextWriter
的用法示例。
在下文中一共展示了JsonTextWriter.WriteEndObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Contracts
//IEnumerable<T> WhereActiveOrderBy(
//REFACTOR: we're building things up in memory, and inefficiently as well...
//MESS: NAIVE: these are nasty messes of code as well.
public ActionResult Contracts()
{
//get a list with the newest employees/offices for each employee/office code.
var newestOffices = db.newestOffices();
var newestEmployees = db.newestEmployees();
return authenticatedAction(new String[] { "UT", "UR" }, () => {
content:
var result = makeJSONResult();
using (JsonTextWriter w = new JsonTextWriter()) {
w.WriteStartArray();
foreach (Contract c in db.Contracts.WAOBTL()) {
w.writeSharedJSONMembers(c);
w.writeSharedJSONProlog();
foreach (Company co in db.Companies.Where(tco => tco.contractCode == c.code).WAOBTL()) {
w.writeSharedJSONMembers(co);
w.WriteMember("offices");
w.WriteStartArray();
foreach (Office o in newestOffices
.Where(o => o.companyCode == co.code)
.Where(o => o.contractCode == c.code)
.WAOBTL()
) {
w.WriteStartObject();
//LOOK AT THIS! WE'RE NOT JUST SENDING OVER THE CODE, BUT THE VERSION AS WELL!
w.WriteMember("code");
w.WriteString(o.code + "?" + o.version.ToString());
w.WriteMember("description");
w.WriteString(o.description);
w.WriteEndObject();
}
w.WriteEndArray();
w.WriteMember("employees");
w.WriteStartArray();
foreach (Employee e in newestEmployees
.Where(e => e.companyCode == co.code)
.Where(e => e.contractCode == c.code)
.WAOBTL()) {
w.WriteStartObject();
//LOOK AT THIS! WE'RE NOT JUST SENDING OVER THE CODE, BUT THE VERSION AS WELL!
w.WriteMember("code");
w.WriteString(e.code + "?" + e.version.ToString());
w.WriteMember("description");
w.WriteString(e.firstName + " " + e.lastName);
w.WriteEndObject();
}
w.WriteEndArray();
w.WriteEndObject();
}
w.writeSharedJSONEpilog();
}
w.WriteEndArray();
result.Content = w.ToString();
}
logger.Debug("TreesController.Contracts accessed.");
return result;
});
}
示例2: Example
public void Example()
{
#region Usage
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
using (JsonWriter writer = new JsonTextWriter(sw))
{
writer.Formatting = Formatting.Indented;
writer.WriteStartObject();
writer.WritePropertyName("CPU");
writer.WriteValue("Intel");
writer.WritePropertyName("PSU");
writer.WriteValue("500W");
writer.WritePropertyName("Drives");
writer.WriteStartArray();
writer.WriteValue("DVD read/writer");
writer.WriteComment("(broken)");
writer.WriteValue("500 gigabyte hard drive");
writer.WriteValue("200 gigabype hard drive");
writer.WriteEnd();
writer.WriteEndObject();
}
Console.WriteLine(sb.ToString());
// {
// "CPU": "Intel",
// "PSU": "500W",
// "Drives": [
// "DVD read/writer"
// /*(broken)*/,
// "500 gigabyte hard drive",
// "200 gigabype hard drive"
// ]
// }
#endregion
Assert.AreEqual(@"{
""CPU"": ""Intel"",
""PSU"": ""500W"",
""Drives"": [
""DVD read/writer""
/*(broken)*/,
""500 gigabyte hard drive"",
""200 gigabype hard drive""
]
}", sb.ToString());
}
示例3: EndRequest
public override void EndRequest()
{
base.EndRequest();
Context.Response.ContentType = "application/json";
using (var streamWriter = new StreamWriter(Context.Response.OutputStream))
using (var writer = new JsonTextWriter(streamWriter))
{
writer.WriteStartObject();
writer.WritePropertyName("c");
writer.WriteValue(_channelId);
writer.WriteEndObject();
}
}
示例4: ReadingAndWritingJsonText
public void ReadingAndWritingJsonText()
{
#region ReadingAndWritingJsonText
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
using (JsonWriter writer = new JsonTextWriter(sw))
{
writer.Formatting = Formatting.Indented;
writer.WriteStartObject();
writer.WritePropertyName("CPU");
writer.WriteValue("Intel");
writer.WritePropertyName("PSU");
writer.WriteValue("500W");
writer.WritePropertyName("Drives");
writer.WriteStartArray();
writer.WriteValue("DVD read/writer");
writer.WriteComment("(broken)");
writer.WriteValue("500 gigabyte hard drive");
writer.WriteValue("200 gigabype hard drive");
writer.WriteEnd();
writer.WriteEndObject();
}
// {
// "CPU": "Intel",
// "PSU": "500W",
// "Drives": [
// "DVD read/writer"
// /*(broken)*/,
// "500 gigabyte hard drive",
// "200 gigabype hard drive"
// ]
// }
#endregion
}
示例5: ToJson
public static string ToJson(this Person p)
{
StringWriter sw = new StringWriter();
JsonTextWriter writer = new JsonTextWriter(sw);
// {
writer.WriteStartObject();
// "name" : "Jerry"
writer.WritePropertyName("name");
writer.WriteValue(p.Name);
// "likes": ["Comedy", "Superman"]
writer.WritePropertyName("likes");
writer.WriteStartArray();
foreach (string like in p.Likes)
{
writer.WriteValue(like);
}
writer.WriteEndArray();
// }
writer.WriteEndObject();
return sw.ToString();
}
示例6: SerializeMessage
public static void SerializeMessage(JsonTextWriter writer, ServiceType type, object message)
{
Require.NotNull(writer, "writer");
Require.NotNull(type, "type");
Require.NotNull(message, "message");
writer.WriteStartObject();
foreach (var field in type.Fields.Values)
{
if (
field.ShouldSerializeMethod != null &&
!field.ShouldSerializeMethod(message)
)
continue;
writer.WritePropertyName(field.Tag.ToString(CultureInfo.InvariantCulture));
object value = field.Getter(message);
if (value == null)
{
writer.WriteNull();
}
else if (field.CollectionType != null)
{
writer.WriteStartArray();
foreach (object item in (IEnumerable)value)
{
if (field.ServiceType != null && !field.ServiceType.Type.IsEnum)
SerializeMessage(writer, field.ServiceType, item);
else
writer.WriteValue(item);
}
writer.WriteEndArray();
}
else
{
if (field.ServiceType != null && !field.ServiceType.Type.IsEnum)
SerializeMessage(writer, field.ServiceType, value);
else
writer.WriteValue(value);
}
}
writer.WriteEndObject();
}
示例7: WriteList
void WriteList(JsonTextWriter writer, ListStatuses list)
{
writer.WriteStartObject ();
writer.WriteKey ("id");
writer.WriteNumber (list.List.ID);
writer.WriteKey ("username");
writer.WriteString (list.Account.ScreenName);
WriteRestUsage (writer, list.RestInfo);
writer.WriteEndObject ();
}
示例8: WriteSearch
void WriteSearch(JsonTextWriter writer, SearchStatuses search)
{
writer.WriteStartObject ();
writer.WriteKey ("keywords");
writer.WriteString (search.Keyword);
writer.WriteKey ("username");
writer.WriteString (search.Account.ScreenName);
WriteRestUsage (writer, search.RestInfo);
writer.WriteEndObject ();
}
示例9: Save
public void Save(ConfigSaveDelegate save)
{
using (StreamWriter streamWriter = new StreamWriter (ConfigFilePath, false, System.Text.Encoding.UTF8))
using (JsonTextWriter writer = new JsonTextWriter (streamWriter)) {
writer.WriteStartObject ();
writer.WriteKey ("accounts");
writer.WriteStartArray ();
for (int i = 0; i < _accounts.Length; i ++)
WriteAccount (writer, _accounts[i]);
writer.WriteEndArray ();
writer.WriteKey ("searches");
writer.WriteStartArray ();
for (int i = 0; i < _searches.Length; i ++)
WriteSearch (writer, _searches[i]);
writer.WriteEndArray ();
writer.WriteKey ("lists");
writer.WriteStartArray ();
for (int i = 0; i < _lists.Length; i++)
WriteList (writer, _lists[i]);
writer.WriteEndArray ();
save (writer);
writer.WriteEndObject ();
}
}
示例10: WriteAccount
void WriteAccount(JsonTextWriter writer, TwitterAccount account)
{
writer.WriteStartObject ();
if (account.Credential is NetworkCredential) {
NetworkCredential nc = account.Credential as NetworkCredential;
writer.WriteKey ("username");
writer.WriteString (nc.UserName);
writer.WriteKey ("password");
writer.WriteString (nc.Password);
} else if (account.Credential is OAuthPasswordCache) {
OAuthPasswordCache pc = account.Credential as OAuthPasswordCache;
writer.WriteKey ("username");
writer.WriteString (pc.UserName);
writer.WriteKey ("password");
writer.WriteString (pc.Password);
writer.WriteKey ("token");
writer.WriteString (pc.AccessToken);
writer.WriteKey ("secret");
writer.WriteString (pc.AccessSecret);
}
if (account.SelfUserID > 0) {
writer.WriteKey ("id");
writer.WriteNumber (account.SelfUserID);
}
writer.WriteKey ("rest");
writer.WriteStartObject ();
string[] rest_keys = new string[] {"home", "mentions", "dm"};
TwitterAccount.RestUsage[] rests = new TwitterAccount.RestUsage[] {account.RestHome, account.RestMentions, account.RestDirectMessages};
for (int i = 0; i < rest_keys.Length; i ++) {
writer.WriteKey (rest_keys[i]);
writer.WriteStartObject ();
writer.WriteKey ("enable");
writer.WriteBoolean (rests[i].IsEnabled);
writer.WriteKey ("count");
writer.WriteNumber (rests[i].Count);
writer.WriteKey ("interval");
writer.WriteNumber ((int)rests[i].Interval.TotalSeconds);
writer.WriteEndObject ();
}
writer.WriteEndObject ();
writer.WriteKey ("streaming");
if (account.StreamingClient == null) {
writer.WriteNull ();
} else {
writer.WriteStartObject ();
writer.WriteKey ("mode");
if (account.StreamingClient.Target is TwitterAccount) {
writer.WriteString ("follow");
writer.WriteKey ("username");
writer.WriteString ((account.StreamingClient.Target as TwitterAccount).ScreenName);
} else if (account.StreamingClient.Target is SearchStatuses) {
writer.WriteString ("track");
writer.WriteKey ("keywords");
writer.WriteString (account.StreamingClient.SearchKeywords);
} else if (account.StreamingClient.Target is ListStatuses) {
writer.WriteString ("list");
writer.WriteKey ("id");
writer.WriteNumber ((account.StreamingClient.Target as ListStatuses).List.ID);
}
writer.WriteEndObject ();
}
writer.WriteEndObject ();
}
示例11: ProcessRequest
protected override void ProcessRequest()
{
string httpMethod = Request.RequestType;
if (!CaselessString.Equals(httpMethod, "GET") &&
!CaselessString.Equals(httpMethod, "HEAD"))
{
throw new JsonRpcException(string.Format("HTTP {0} is not supported for RPC execution. Use HTTP GET or HEAD only.", httpMethod));
}
//
// Response will be plain text, though it would have been nice to
// be more specific, like text/json.
//
Response.ContentType = "text/plain";
//
// Convert the query string into a call object.
//
JsonWriter writer = new JsonTextWriter();
writer.WriteStartObject();
writer.WriteMember("id");
writer.WriteNumber(0);
writer.WriteMember("method");
string methodName = Mask.NullString(Request.PathInfo);
if (methodName.Length == 0)
writer.WriteNull();
else
writer.WriteString(methodName.Substring(1));
writer.WriteMember("params");
writer.WriteStartObject();
NameValueCollection query = Request.QueryString;
if (query.HasKeys())
{
foreach (string name in query)
{
if (Mask.NullString(name).Length == 0)
continue;
writer.WriteMember(name);
string[] values = query.GetValues(name);
if (values.Length == 0)
writer.WriteNull();
else if (values.Length == 1)
writer.WriteString(values[0]);
else
writer.WriteArray(values);
}
}
writer.WriteEndObject();
writer.WriteEndObject();
//
// Delegate rest of the work to JsonRpcDispatcher.
//
JsonRpcDispatcher dispatcher = new JsonRpcDispatcher(Service);
if (HttpRequestSecurity.IsLocal(Request))
dispatcher.SetLocalExecution();
dispatcher.Process(new StringReader(writer.ToString()), Response.Output);
}
示例12: BuildResponseJson
private void BuildResponseJson(StringBuilder sb, PendingDownstreamMessage message)
{
using (var stringWriter = new StringWriter(sb))
using (var writer = new JsonTextWriter(stringWriter))
{
if (message == null)
{
writer.WriteStartArray();
writer.WriteValue("noop");
writer.WriteEndArray();
}
else
{
var responseType = message.Message.GetType();
var responseServiceType = ServiceRegistry.GetAssembly(responseType.Assembly).TypesByType[responseType];
writer.WriteStartObject();
writer.WritePropertyName("r");
writer.WriteValue((int)message.Kind);
writer.WritePropertyName("a");
writer.WriteValue((int)message.AssociationId);
writer.WritePropertyName("t");
writer.WriteValue(responseServiceType.Message.Id);
writer.WritePropertyName("p");
JsonUtil.SerializeMessage(writer, responseServiceType, message.Message);
writer.WriteEndObject();
}
}
}
示例13: SaveConfigInternalStyles
void SaveConfigInternalStyles(JsonTextWriter writer)
{
writer.WriteStartObject ();
writer.WriteKey ("colors");
writer.WriteStartObject ();
SaveConfigInternalColors (writer);
writer.WriteEndObject ();
writer.WriteKey ("fonts");
writer.WriteStartObject ();
SaveConfigInternalFonts (writer);
writer.WriteEndObject ();
writer.WriteKey ("icon_size");
writer.WriteNumber (IconSize);
writer.WriteEndObject ();
}
示例14: SaveConfigInternalMisc
void SaveConfigInternalMisc(JsonTextWriter writer)
{
writer.WriteStartObject ();
writer.WriteKey ("include_mentions");
writer.WriteBoolean (_mgr.HomeIncludeMentions);
writer.WriteEndObject ();
}
示例15: SaveConfigInternal
void SaveConfigInternal(JsonTextWriter writer, TimelineBase timelines)
{
foreach (object item in timelines.TimeLines) {
writer.WriteStartObject ();
writer.WriteKey ("type");
TimelineInfo tl = item as TimelineInfo;
TabInfo tb = item as TabInfo;
if (tl != null) {
if (tl.Search != null) {
writer.WriteString ("search");
writer.WriteKey ("keywords");
writer.WriteString (tl.Search.Keyword);
} else if (tl.List != null) {
writer.WriteString ("list");
writer.WriteKey ("id");
writer.WriteNumber (tl.List.List.ID);
} else {
writer.WriteString ("account");
writer.WriteKey ("subtype");
if (tl.Statuses == tl.RestAccount.HomeTimeline)
writer.WriteString ("home");
else if (tl.Statuses == tl.RestAccount.Mentions)
writer.WriteString ("mentions");
else if (tl.Statuses == tl.RestAccount.DirectMessages)
writer.WriteString ("directmessages");
writer.WriteKey ("name");
writer.WriteString (tl.RestAccount.ScreenName);
}
} else if (tb != null) {
writer.WriteString ("tab");
writer.WriteKey ("title");
writer.WriteString (tb.Title);
writer.WriteKey ("windows");
writer.WriteStartArray ();
SaveConfigInternal (writer, tb);
writer.WriteEndArray ();
} else {
writer.WriteNull ();
}
writer.WriteEndObject ();
}
}