当前位置: 首页>>代码示例>>C#>>正文


C# JsonTextWriter.ToString方法代码示例

本文整理汇总了C#中JsonTextWriter.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextWriter.ToString方法的具体用法?C# JsonTextWriter.ToString怎么用?C# JsonTextWriter.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonTextWriter的用法示例。


在下文中一共展示了JsonTextWriter.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Format

 private static string Format(object o)
 {
     JsonTextWriter writer = new JsonTextWriter();
     writer.ValueFormatter = new DateTimeFormatter();
     writer.WriteValue(o);
     return writer.ToString();
 }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:7,代码来源:TestDateTimeFormatter.cs

示例2: 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;
            });
        }
开发者ID:rplacd,项目名称:RedTelephone,代码行数:61,代码来源:TreesController.cs

示例3: ExactSelection

 public void ExactSelection()
 {
     JsonTextWriter writer = new JsonTextWriter();
     CompositeFormatter compositeFormatter = new CompositeFormatter();
     compositeFormatter.AddFormatter(typeof(object), new TestFormatter());
     IJsonFormatter formatter = compositeFormatter.SelectFormatter(typeof(object));
     formatter.Format(new object(), writer);
     Assert.AreEqual("\"(object)\"", writer.ToString());
 }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:9,代码来源:TestCompositeFormatter.cs

示例4: Export

 public void Export()
 {
     ControlExporter exporter = new ControlExporter();
     JsonTextWriter writer = new JsonTextWriter();
     HtmlGenericControl span = new HtmlGenericControl("span");
     span.InnerText = "Happy & shiny people!";
     exporter.Export(new ExportContext(), span, writer);
     Assert.AreEqual("[\"<span>Happy &amp; shiny people!<\\/span>\"]", writer.ToString());
 }
开发者ID:bubbafat,项目名称:Hebo,代码行数:9,代码来源:TestControlExporter.cs

示例5: Formatting

 public void Formatting()
 {
     ControlFormatter formatter = new ControlFormatter();
     JsonTextWriter writer = new JsonTextWriter();
     HtmlGenericControl span = new HtmlGenericControl("span");
     span.InnerText = "Happy & shiny people!";
     formatter.Format(span, writer);
     Assert.AreEqual("\"<span\\>Happy &amp; shiny people!</span\\>\"", writer.ToString());
 }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:9,代码来源:TestControlFormatter.cs

示例6: Format

        private static string Format(object o)
        {
            ComponentFormatter componentFormatter = new ComponentFormatter();

            CompositeFormatter compositeFormatter = new CompositeFormatter();
            compositeFormatter.AddFormatter(typeof(Car), componentFormatter);
            compositeFormatter.AddFormatter(typeof(Person), componentFormatter);

            JsonTextWriter writer = new JsonTextWriter();
            writer.ValueFormatter = compositeFormatter;

            writer.WriteValue(o);
            return writer.ToString();
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:14,代码来源:TestComponentFormatter.cs

示例7: Format

 private static string Format(DataTable table)
 {
     JsonTextWriter writer = new JsonTextWriter();
     JsonConvert.Export(new FakeDataTableReader(table), writer);
     return writer.ToString();
 }
开发者ID:db48x,项目名称:KeeFox,代码行数:6,代码来源:TestDbDataRecordExporter.cs

示例8: CustomPropertiesInternally

 public void CustomPropertiesInternally()
 {
     Point point = new Point(123, 456);
     JsonTextWriter writer = new JsonTextWriter();
     writer.WriteValue(point);
     Assert.AreEqual("{\"X\":123,\"Y\":456}", writer.ToString());
 }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:7,代码来源:TestComponentFormatter.cs

示例9: FormatForReading

        private static JsonReader FormatForReading(object o)
        {
            CompositeFormatter compositeFormatter = new CompositeFormatter();
            compositeFormatter.AddFormatter(typeof(Car), new ComponentFormatter());
            compositeFormatter.AddFormatter(typeof(Person), new ComponentFormatter());
            compositeFormatter.AddFormatter(typeof(OwnerCars), new ComponentFormatter());

            JsonTextWriter writer = new JsonTextWriter();
            writer.ValueFormatter = compositeFormatter;

            writer.WriteValue(o);
            return new JsonTextReader(new StringReader(writer.ToString()));
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:13,代码来源:TestComponentFormatter.cs

示例10: Export

 private static string Export(object o)
 {
     JsonTextWriter writer = new JsonTextWriter();
     JsonConvert.Export(o, writer);
     return writer.ToString();
 }
开发者ID:atifaziz,项目名称:Jayrock,代码行数:6,代码来源:TestNameValueCollectionExporter.cs

示例11: Format

 private static string Format(object o)
 {
     JsonTextWriter writer = new JsonTextWriter();
     (new ExportContext()).Export(o, writer);
     return writer.ToString();
 }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:6,代码来源:TestComponentExporter.cs

示例12: Export

 private static string Export(object o)
 {
     JsonTextWriter writer = new JsonTextWriter();
     writer.WriteValue(o);
     return writer.ToString();
 }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:6,代码来源:TestNameValueCollectionExporter.cs

示例13: Format

        private static string Format(object o)
        {
            JsonTextWriter writer = new JsonTextWriter();
            writer.ValueFormatter = new NameValueCollectionFormatter();

            writer.WriteValue(o);
            return writer.ToString();
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:8,代码来源:TestNameValueCollectionFormatter.cs

示例14: 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);
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:75,代码来源:JsonRpcGetProtocol.cs

示例15: Sources

 public ActionResult Sources()
 {
     return authenticatedAction(new String[] { "UT", "UR" }, () => {
         var result = makeJSONResult();
         using (JsonTextWriter w = new JsonTextWriter()) {
             w.WriteStartArray();
             foreach (IssueSourceLvl1 i in db.IssueSourceLvl1s.WAOBTL()) {
                 w.writeSharedJSONMembers(i);
                 w.writeSharedJSONProlog();
                 foreach (IssueSourceLvl2 i2 in db.IssueSourceLvl2s.Where(ti2 => ti2.parentCode == i.code).WAOBTL()) {
                     w.writeSharedJSONMembers(i2);
                     w.writeSharedJSONProlog();
                     foreach (IssueSourceLvl3 i3 in db.IssueSourceLvl3s
                         .Where(ti3 => ti3.grandparentCode == i.code)
                         .Where(ti3 => ti3.parentCode == i2.code)
                         .WAOBTL()) {
                         w.writeSharedJSONMembers(i3);
                         w.WriteEndObject();
                     }
                     w.writeSharedJSONEpilog();
                 }
                 w.writeSharedJSONEpilog();
             }
             w.WriteEndArray();
             result.Content = w.ToString();
         }
         logger.Debug("TreesController.Sources accessed.");
         return result;
     });
 }
开发者ID:rplacd,项目名称:RedTelephone,代码行数:30,代码来源:TreesController.cs


注:本文中的JsonTextWriter.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。