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


C# JsonTextWriter.WriteNull方法代码示例

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


在下文中一共展示了JsonTextWriter.WriteNull方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
                    }
                }
            }
        }
开发者ID:cupsster,项目名称:litjson,代码行数:57,代码来源:BmJayrockWriter.cs

示例2: 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));
            }

            string callback = Mask.NullString(Request.QueryString["jsonp"]);
            bool padded = callback.Length > 0;
            
            //
            // The response type depends on whether JSONP (JSON with 
            // Padding) is in effect or not.
            //

            Response.ContentType = padded ? "text/javascript" : "application/json";
            
            //
            // Validate that the JSONP callback method conforms to the 
            // allowed syntax. If not, issue a client-side exception
            // that will certainly help to bring problem to light, even if
            // a little too aggressively.
            //
            
            if (padded)
            {
                if (!_jsonpex.IsMatch(callback))
                {
                    Response.Write("throw new Error('Invalid JSONP callback parameter value.');");
                    Response.End();
                }
            }
            
            //
            // Convert the query string into a call object.
            //

            JsonWriter writer = new JsonTextWriter();
            
            writer.WriteStartObject();
            
            writer.WriteMember("id");
            writer.WriteNumber(-1);
            
            writer.WriteMember("method");
            
            string methodName = Mask.NullString(Request.PathInfo);
            
            if (methodName.Length == 0)
            {
                writer.WriteNull();
            }
            else
            {
                //
                // If the method name contains periods then we replace it
                // with dashes to mean the one and same thing. This is
                // done to provide dashes as an alternative to some periods
                // since some web servers may block requests (for security
                // reasons) if a path component of the URL contains more
                // than one period.
                //
                
                writer.WriteString(methodName.Substring(1).Replace('-', '.'));
            }
            
            writer.WriteMember("params");
            NameValueCollection query = new NameValueCollection(Request.QueryString);
            query.Remove(string.Empty);
            JsonConvert.Export(Request.QueryString, writer);
            
            writer.WriteEndObject();
            
            //
            // Delegate rest of the work to JsonRpcDispatcher.
            //

            JsonRpcDispatcher dispatcher = new JsonRpcDispatcher(Service);
            using (new JsonRpcDispatchScope(dispatcher, Context))
            {
                dispatcher.RequireIdempotency = true;

                if (padded)
                {
                    //
                    // For JSONP, see details here:
                    // http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/
                    //

                    Response.Write(callback);
                    Response.Write('(');
                }

                dispatcher.Process(new StringReader(writer.ToString()), Response.Output);

                if (padded)
                    Response.Write(')');
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:101,代码来源:JsonRpcGetProtocol.cs

示例3: WriteNull

 public void WriteNull()
 {
     JsonTextWriter writer = new JsonTextWriter(new StringWriter());
     writer.WriteNull();
     Assert.AreEqual("[null]", writer.ToString());
 }
开发者ID:db48x,项目名称:KeeFox,代码行数:6,代码来源:TestJsonTextWriter.cs

示例4: 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(-1);

            writer.WriteMember("method");

            string methodName = Mask.NullString(Request.PathInfo);

            if (methodName.Length == 0)
            {
                writer.WriteNull();
            }
            else
            {
                //
                // If the method name contains periods then we replace it
                // with dashes to mean the one and same thing. This is
                // done to provide dashes as an alternative to some periods
                // since some web servers may block requests (for security
                // reasons) if a path component of the URL contains more
                // than one period.
                //

                writer.WriteString(methodName.Substring(1).Replace('-', '.'));
            }

            writer.WriteMember("params");
            NameValueCollection query = new NameValueCollection(Request.QueryString);
            query.Remove(string.Empty);
            JsonConvert.Export(Request.QueryString, writer);

            writer.WriteEndObject();

            //
            // Delegate rest of the work to JsonRpcDispatcher.
            //

            JsonRpcDispatcher dispatcher = new JsonRpcDispatcher(Service);

            dispatcher.RequireIdempotency = true;

            if (HttpRequestSecurity.IsLocal(Request))
                dispatcher.SetLocalExecution();

            dispatcher.Process(new StringReader(writer.ToString()), Response.Output);
        }
开发者ID:BackupTheBerlios,项目名称:tamjb,代码行数:70,代码来源:JsonRpcGetProtocol.cs

示例5: 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();
        }
开发者ID:dtsagile,项目名称:arcstache,代码行数:34,代码来源:GISSerializableDictionary.cs

示例6: 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");
//.........这里部分代码省略.........
开发者ID:chenchen2015,项目名称:litjson,代码行数:101,代码来源:BmJayrockOutput.cs


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