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


C# JsonWriter.WriteArrayEnd方法代码示例

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


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

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

            }
        }
开发者ID:chenchen2015,项目名称:litjson,代码行数:58,代码来源:BmLitJsonWriter.cs

示例2: ErrorExcessDataTest

        public void ErrorExcessDataTest()
        {
            JsonWriter writer = new JsonWriter ();

            writer.WriteArrayStart ();
            writer.Write (true);
            writer.WriteArrayEnd ();
            writer.Write (false);
        }
开发者ID:kvantetore,项目名称:litjson,代码行数:9,代码来源:JsonWriterTest.cs

示例3: ErrorObjectClosingTest

        public void ErrorObjectClosingTest()
        {
            JsonWriter writer = new JsonWriter ();

            writer.WriteObjectStart ();
            writer.WritePropertyName ("foo");
            writer.Write ("bar");
            writer.WriteArrayEnd ();
        }
开发者ID:kvantetore,项目名称:litjson,代码行数:9,代码来源:JsonWriterTest.cs

示例4: BooleansTest

        public void BooleansTest()
        {
            JsonWriter writer = new JsonWriter ();

            writer.WriteArrayStart ();
            writer.Write (true);
            writer.Write (false);
            writer.Write (false);
            writer.Write (true);
            writer.WriteArrayEnd ();
        }
开发者ID:kvantetore,项目名称:litjson,代码行数:11,代码来源:JsonWriterTest.cs

示例5: ToNetMsg

        public static void ToNetMsg(Dictionary<long, F3_NetServerInfo> servers, ref NetOutgoingMessage netMsg)
        {
            netMsg.Write((byte)NetDataType.eDATA_REQUEST_SERVER_LIST);

            StringBuilder sb = new StringBuilder();
            JsonWriter writer = new JsonWriter(sb);

            writer.WriteObjectStart();
            writer.WritePropertyName("servers");
            writer.WriteArrayStart();

            for (int i = 0; i < servers.Count; i++)
            {
                F3_NetServerInfo info = servers.ElementAt(i).Value;
                writer.WriteObjectStart();

                writer.WritePropertyName("UUID");
                writer.Write(servers.ElementAt(i).Key);

                writer.WritePropertyName("serverName");
                writer.Write(info.m_serverName);

                writer.WritePropertyName("type");
                writer.Write((int)info.m_serverType);

                writer.WritePropertyName("internal_ip");
                writer.Write(info.m_serverInternalAdress.Address.ToString());

                writer.WritePropertyName("internal_port");
                writer.Write(info.m_serverInternalAdress.Port);

                writer.WritePropertyName("external_ip");
                writer.Write(info.m_serverExternalAdress.Address.ToString());

                writer.WritePropertyName("external_port");
                writer.Write(info.m_serverExternalAdress.Port);

                writer.WritePropertyName("maxPlayers");
                writer.Write(info.m_maxPlayers);

                writer.WritePropertyName("currentPlayers");
                writer.Write(info.m_currentNbPlayers);

                writer.WritePropertyName("token");
                writer.Write(info.m_NATtoken);

                writer.WriteObjectEnd();
            }

            writer.WriteArrayEnd();
            writer.WriteObjectEnd();

            netMsg.Write(sb.ToString());
        }
开发者ID:SharpEdgeEntertainment,项目名称:FrozenFlameFramework,代码行数:54,代码来源:F3.+NetMessageRequestServerList.cs

示例6: 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();
 }
开发者ID:mscottford,项目名称:Cuke4Nuke,代码行数:17,代码来源:StepDefinitionRepository.cs

示例7: LitJsonWriterNumbers

        public static void LitJsonWriterNumbers ()
        {
            for (int i = 0; i < Common.Iterations; i++) {
                StringBuilder output = new StringBuilder ();
                JsonWriter writer = new JsonWriter (new StringWriter (output));

                writer.WriteArrayStart ();

                foreach (int n in Common.SampleInts)
                    writer.Write (n);

                foreach (double n in Common.SampleDoubles)
                    writer.Write (n);

                writer.WriteArrayEnd ();
            }
        }
开发者ID:chenchen2015,项目名称:litjson,代码行数:17,代码来源:BmLitJsonWriter.cs

示例8: ReadInto

        private void ReadInto(JsonReader reader, JsonWriter jsonWriter, bool firstLevel, out Type type, out IJsonRpcTypeResolver resolver)
        {
            type = null;
            resolver = null;

            while (reader.Read()) {
                if (reader.Token == JsonToken.PropertyName) {
                    string propertyName = (string)reader.Value;

                    if (firstLevel && propertyName == "$type") {
                        if (!reader.Read())
                            throw new FormatException();
                        if (reader.Token != JsonToken.String)
                            throw new FormatException();

                        string typeString = (string)reader.Value;

                        type = ResolveType(typeString, out resolver);
                        if (type == null)
                            throw new FormatException();
                    } else {
                        jsonWriter.WritePropertyName(propertyName);
                    }
                } else if (reader.Token == JsonToken.Boolean) {
                    jsonWriter.Write((bool)reader.Value);
                } else if (reader.Token == JsonToken.Int) {
                    jsonWriter.Write((int)reader.Value);
                } else if (reader.Token == JsonToken.Long) {
                    jsonWriter.Write((long)reader.Value);
                } else if (reader.Token == JsonToken.Double) {
                    jsonWriter.Write((double)reader.Value);
                } else if (reader.Token == JsonToken.String) {
                    jsonWriter.Write((string)reader.Value);
                } else if (reader.Token == JsonToken.Null) {
                    jsonWriter.Write(null);
                } else if (reader.Token == JsonToken.ArrayStart) {
                    jsonWriter.WriteArrayStart();

                    while (reader.Read()) {
                        Type dummyType;
                        IJsonRpcTypeResolver dummyResolver;
                        ReadInto(reader, jsonWriter, false, out dummyType, out dummyResolver);
                        if (reader.Token == JsonToken.ArrayEnd) {
                            jsonWriter.WriteArrayEnd();
                            break;
                        }
                    }
                } else if (reader.Token == JsonToken.ObjectEnd) {
                    jsonWriter.WriteObjectEnd();
                    break;
                }
            }
        }
开发者ID:ikvm,项目名称:cloudb,代码行数:53,代码来源:JsonRpcMessageSerializer.cs

示例9: PrettyPrintTest

        public void PrettyPrintTest()
        {
            JsonWriter writer = new JsonWriter ();

            string json = @"
            [
            {
            ""precision"" : ""zip"",
            ""Latitude""  : 37.7668,
            ""Longitude"" : -122.3959,
            ""City""      : ""SAN FRANCISCO""
            },
              {
            ""precision"" : ""zip"",
            ""Latitude""  : 37.371991,
            ""Longitude"" : -122.02602,
            ""City""      : ""SUNNYVALE""
              }
            ]";

            writer.PrettyPrint = true;

            writer.WriteArrayStart ();
            writer.WriteObjectStart ();
            writer.WritePropertyName ("precision");
            writer.Write ("zip");
            writer.WritePropertyName ("Latitude");
            writer.Write (37.7668);
            writer.WritePropertyName ("Longitude");
            writer.Write (-122.3959);
            writer.WritePropertyName ("City");
            writer.Write ("SAN FRANCISCO");
            writer.WriteObjectEnd ();

            writer.IndentValue = 2;

            writer.WriteObjectStart ();
            writer.WritePropertyName ("precision");
            writer.Write ("zip");
            writer.WritePropertyName ("Latitude");
            writer.Write (37.371991);
            writer.WritePropertyName ("Longitude");
            writer.Write (-122.02602);
            writer.WritePropertyName ("City");
            writer.Write ("SUNNYVALE");
            writer.WriteObjectEnd ();
            writer.WriteArrayEnd ();

            Assert.AreEqual (writer.ToString (), json);
        }
开发者ID:kvantetore,项目名称:litjson,代码行数:50,代码来源:JsonWriterTest.cs

示例10: NumbersTest

        public void NumbersTest()
        {
            JsonWriter writer = new JsonWriter ();

            writer.WriteArrayStart ();
            writer.Write (0);
            writer.Write (100);
            writer.Write ((byte) 200);
            writer.Write (-256);
            writer.Write (10000000000l);
            writer.Write ((decimal) 0.333);
            writer.Write ((float) 0.0001);
            writer.Write (9e-20);
            writer.Write (2.3e8);
            writer.Write (Math.PI);
            writer.WriteArrayEnd ();
        }
开发者ID:kvantetore,项目名称:litjson,代码行数:17,代码来源:JsonWriterTest.cs

示例11: NullTextWriterTest

        public void NullTextWriterTest()
        {
            JsonWriter writer = new JsonWriter (TextWriter.Null);

            writer.WriteArrayStart ();
            writer.Write ("Hello");
            writer.Write ("World");
            writer.WriteArrayEnd ();
        }
开发者ID:kvantetore,项目名称:litjson,代码行数:9,代码来源:JsonWriterTest.cs

示例12: 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();
            }
开发者ID:ikvm,项目名称:cloudb,代码行数:43,代码来源:JsonRpcMessageSerializer.cs

示例13: LitJsonOutputFile

        public static void LitJsonOutputFile ()
        {
            using (FileStream fs = new FileStream ("litjson_out.txt",
                                                   FileMode.Create)) {
                StreamWriter out_stream = new StreamWriter (fs);

                JsonReader reader = new JsonReader (Common.JsonText);

                out_stream.WriteLine ("*** Reading with LitJson.JsonReader");

                while (reader.Read ()) {
                    out_stream.Write ("Token: {0}", reader.Token);

                    if (reader.Value != null)
                        out_stream.WriteLine (" Value: {0}", reader.Value);
                    else
                        out_stream.WriteLine ("");
                }


                out_stream.WriteLine (
                    "\n*** Writing with LitJson.JsonWriter");

                JsonWriter writer = new JsonWriter (out_stream);
                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;
                    }
                }


                out_stream.WriteLine (
                    "\n\n*** Data imported with " +
                    "LitJson.JsonMapper\n");

                Person art = JsonMapper.ToObject<Person> (Common.PersonJson);

                out_stream.Write (art.ToString ());


                out_stream.WriteLine (
                    "\n\n*** Object exported with " +
                    "LitJson.JsonMapper\n");

                out_stream.Write (JsonMapper.ToJson (Common.SamplePerson));


                out_stream.WriteLine (
                    "\n\n*** Generic object exported with " +
                    "LitJson.JsonMapper\n");

                JsonData person = JsonMapper.ToObject (Common.PersonJson);

                out_stream.Write (JsonMapper.ToJson (person));


//.........这里部分代码省略.........
开发者ID:chenchen2015,项目名称:litjson,代码行数:101,代码来源:BmLitJsonOutput.cs

示例14: WriteJson

        private static void WriteJson(IJsonWrapper obj, JsonWriter writer)
        {
            if (obj.IsString) {
                writer.Write (obj.GetString ());
                return;
            }

            if (obj.IsBoolean) {
                writer.Write (obj.GetBoolean ());
                return;
            }

            if (obj.IsDouble) {
                writer.Write (obj.GetDouble ());
                return;
            }

            if (obj.IsInt) {
                writer.Write (obj.GetInt ());
                return;
            }

            if (obj.IsLong) {
                writer.Write (obj.GetLong ());
                return;
            }

            if (obj.IsArray) {
                writer.WriteArrayStart ();
                foreach (object elem in (IList) obj)
                    WriteJson ((JsonData) elem, writer);
                writer.WriteArrayEnd ();

                return;
            }

            if (obj.IsObject) {
                writer.WriteObjectStart ();

                foreach (DictionaryEntry entry in ((IDictionary) obj)) {
                    writer.WritePropertyName ((string) entry.Key);
                    WriteJson ((JsonData) entry.Value, writer);
                }
                writer.WriteObjectEnd ();

                return;
            }
        }
开发者ID:Cyberspace-Networks,项目名称:PeopleAggregator,代码行数:48,代码来源:JsonData.cs

示例15: LoadWidgets

        public void LoadWidgets(bool exclude_unless_post)
        {
            Debug.Assert(m_setup_complete, "You must call SetupComplete() before LoadWidgets()");
            if (m_widgets_loaded) return; // already loaded - presumably by SetupComplete()
            m_widgets_loaded = true;

            // make request to backend to get widget HTML
            JsonWriter w = new JsonWriter();

            w.WriteObjectStart();

            w.WritePropertyName("modules");
            w.WriteArrayStart();
            foreach (RemoteWidget wi in m_widgets.Values)
            {
                if (exclude_unless_post && wi.Method == "get") continue;
                wi.DumpJson(w);
            }
            w.WriteArrayEnd(); // modules

            w.WritePropertyName("global");
            w.WriteObjectStart();
            w.WritePropertyName("user");
            w.WriteObjectStart();
            w.WritePropertyName("namespace");
            w.Write(m_user_namespace);
            w.WritePropertyName("user_id");
            w.Write(m_user_id); // placeholder for now until we get shadow accounts working
            w.WritePropertyName("email");
            w.Write(m_user_email);
            w.WritePropertyName("first_name");
            w.Write(m_user_first_name);
            w.WritePropertyName("last_name");
            w.Write(m_user_last_name);
            w.WriteObjectEnd(); // user
            w.WriteObjectEnd(); // global

            w.WriteObjectEnd(); // outer

            string json_request = w.ToString();

            // now post the request to the backend server
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(m_remote_url);
            req.Method = "POST";
            req.ContentType = "application/x-javascript";
            byte[] post_data = Encoding.UTF8.GetBytes(json_request);
            req.ContentLength = post_data.Length;
            Stream post_stream = req.GetRequestStream();
            post_stream.Write(post_data, 0, post_data.Length);
            post_stream.Close();

            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
            StreamReader resp_stream = new StreamReader(resp.GetResponseStream());
            /*
            while (true)
            {
                string line = resp_stream.ReadLine();
                if (line == null) break;
                Debug.Print("line from response: " + line);
            }
            */
            string raw_data = resp_stream.ReadToEnd();
            resp.Close();
            string error = null;
            try
            {
                JsonData data = JsonMapper.ToObject(raw_data);

                // http request done - now handle the json response
                if (((IDictionary)data).Contains("error"))
                {
                    error = (string)data["error"];
                }
                else
                {
                    JsonData modules = data["modules"];
                    if (!modules.IsArray) error = "JSON server returned non-array for modules.";
                    else foreach (JsonData module in modules)
                    {
                        string module_id = module["id"].ToString();
                        RemoteWidget wi = (RemoteWidget)m_widgets[module_id];
                        wi.LoadFromJson(module);
                    }
                }
            }
            catch (JsonException)
            {
                error = "BAD JSON RESPONSE FROM WIDGET SERVER: " + raw_data;
            }
            if (error != null)
            {
                foreach (RemoteWidget wi in m_widgets.Values)
                {
                    wi.HTML = m_page.Server.HtmlEncode(error);
                }
            }
        }
开发者ID:Cyberspace-Networks,项目名称:PeopleAggregator,代码行数:97,代码来源:RemoteWidgetController.cs


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