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


C# JsonArray类代码示例

本文整理汇总了C#中JsonArray的典型用法代码示例。如果您正苦于以下问题:C# JsonArray类的具体用法?C# JsonArray怎么用?C# JsonArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: GetAll

        public JsonValue GetAll()
        {
            JsonObject parameters = WebOperationContext.Current.IncomingRequest.GetQueryStringAsJsonObject();

            JsonValue term;
            string termValue = parameters.TryGetValue("term", out term) ? term.ReadAs<string>() : String.Empty;

            using (SqlConnection sc = new SqlConnection(connectionString))
            {
                sc.Open();
                using (SqlCommand getAll = new SqlCommand("SELECT Email FROM Contact WHERE (Email LIKE @term)", sc))
                {
                    getAll.Parameters.AddWithValue("@term", termValue + "%");
                    SqlDataReader reader = getAll.ExecuteReader();

                    JsonArray results = new JsonArray();
                    while (reader.Read())
                    {
                        results.Add(Convert.ToString(reader[0], CultureInfo.InvariantCulture));
                    }

                    return results;
                }
            }
        }
开发者ID:nuxleus,项目名称:WCFWeb,代码行数:25,代码来源:ContactsResource.cs

示例2: PostToWall

        public void PostToWall()
        {
            try
            {
                var actionLinks = new JsonArray();

                var learnMore = new JsonObject();
                learnMore.Add("text", "Learn more about Big Profile");
                learnMore.Add("href", "http://myapp.no/BigProfile");

                var appStore = new JsonObject();
                appStore.Add("text", "Visit App Store");
                appStore.Add("href", "http://myapp.no/BigProfileAppStore");

                //actionLinks.Add(learnMore);
                actionLinks.Add(appStore);

                var attachment = new JsonObject();
                attachment.Add("name", "Big Profile");
                attachment.Add("description", "Make your profile stand out with a big profile picture stretched across the new Facebook design. Available in App Store!");
                attachment.Add("href", "http://myapp.no/BigProfile");

                var parameters = new NSMutableDictionary();
                parameters.Add(new NSString("user_message_prompt"), new NSString("Tell your friends"));
                parameters.Add(new NSString("attachment"), new NSString(attachment.ToString()));
                parameters.Add(new NSString("action_links"), new NSString(actionLinks.ToString()));

                _facebook.Dialog("stream.publish", parameters, facebookDialogDelegate);
            }
            catch(Exception ex)
            {
                Console.WriteLine("Exception when showing dialog: {0}", ex);
            }
        }
开发者ID:follesoe,项目名称:FacebookBigProfile,代码行数:34,代码来源:FacebookController.cs

示例3: Main

        static void Main(string[] args)
        {
            //var json = new JsonArray(
            //    new JsonObject(
            //        new JsonMember("A", new JsonNumber(1)),
            //        new JsonMember("B", new JsonNumber(2)),
            //        new JsonMember("C", new JsonArray(new JsonNumber(1), new JsonNumber(2)))),
            //    new JsonObject(
            //        new JsonMember("D", new JsonNumber(3)),
            //        new JsonMember("E", new JsonNumber(4))));

            var nested = new JsonObject(
                new JsonMember("A", new JsonNumber(3)),
                new JsonMember("A", new JsonNumber(3.01m)),
                new JsonMember("A", new JsonNumber(3)));

            var array = new JsonArray(nested, nested, nested);
            var array2 = new JsonArray(new JsonNumber(3), new JsonNumber(2), new JsonNumber(1));

            JsonValue json = new JsonObject(
                new JsonMember("A", new JsonString("\u0460\u849c\u8089")),
                new JsonMember("B", new JsonNumber(2)),
                new JsonMember("C",
                    new JsonObject(
                        new JsonMember("A", new JsonNumber(3)),
                        new JsonMember("A", new JsonNumber(3)),
                        new JsonMember("A", new JsonNumber(3)),
                        new JsonMember("ComplexArray", array),
                        new JsonMember("SimpleArray", array2))));

            Console.WriteLine(json.Stringify(true));

            json = Json.CreateAst(json.Stringify(true));
            Console.WriteLine(json.Stringify(true));
        }
开发者ID:cosullivan,项目名称:JsonLite,代码行数:35,代码来源:Program.cs

示例4: CreateFromScratch

        private static void CreateFromScratch()
        {
            rootObject = new JsonObject();

            readList = new JsonArray();
            rootObject.Add(ReadListKey, readList);
        }
开发者ID:kiewic,项目名称:Questions,代码行数:7,代码来源:ReadListManager.cs

示例5: CompareJsonArrayTypes

        private static bool CompareJsonArrayTypes(JsonArray objA, JsonArray objB)
        {
            bool retValue = true;

            if (objA == null || objB == null || objA.Count != objB.Count || objA.IsReadOnly != objB.IsReadOnly)
            {
                return false;
            }

            try
            {
                for (int i = 0; i < objA.Count; i++)
                {
                    if (!Compare(objA[i], objB[i]))
                    {
                        Log.Info("JsonValueVerifier (JsonArrayType) Error: objA[{0}] = {1}", i, objA[i].ToString());
                        Log.Info("JsonValueVerifier (JsonArrayType) Error: objB[{0}] = {1}", i, objB[i].ToString());
                        return false;
                    }
                }
            }
            catch (Exception e)
            {
                Log.Info("JsonValueVerifier (JsonArrayType) Error: An Exception was thrown: " + e);
                return false;
            }

            return retValue;
        }
开发者ID:nuxleus,项目名称:WCFWeb,代码行数:29,代码来源:JsonValueTestHelper.cs

示例6: JsonArrayBindingSource

        /// <summary>
        /// Initializes a new instance of <see cref="JsonArrayBindingSource"/> with a source <see cref="JsonArray"/> and the type of <see cref="JsonValue"/> that is contained in the array.
        /// </summary>
        /// <param name="sourceArray">The source array containing values.</param>
        /// <param name="valueType">The type of <see cref="JsonValue"/> the <see cref="JsonArray"/> contains.</param>
        /// <remarks>
        /// If the source <see cref="JsonArray"/> is empty, use the constructor with the constructor <see cref="JsonArrayBindingSource.JsonArrayBindingSource(JsonArray, Type, IEnumerable{JsonObject.JsonObjectPropertyDescriptor})"/> to define the properties that should be available.
        /// </remarks>
        public JsonArrayBindingSource(JsonArray sourceArray, Type valueType)
        {
            _array = sourceArray;
            vtype = valueType;

            if (sourceArray.Count > 0)
                ReadProperties();
            else
            {

                if (valueType == typeof(JsonString) || valueType == typeof(JsonNumber) || valueType == typeof(JsonBoolean))
                {
                    PropertyDescriptorCollection c = TypeDescriptor.GetProperties(valueType);
                    PropertyDescriptor[] ca = new PropertyDescriptor[1];
                    foreach (PropertyDescriptor item in c)
                    {
                        if (item.Name == "Value")
                        {
                            ca[0] = item;
                            props = new PropertyDescriptorCollection(ca);
                            break;
                        }
                    }
                }
                else
                    props = TypeDescriptor.GetProperties(valueType);
            }
        }
开发者ID:troygeiger,项目名称:TG.JSON,代码行数:36,代码来源:JsonArrayBindingSource.cs

示例7: Search

        public async Task<string> Search(string search)
        {
            using (AutoResetEvent handle = new AutoResetEvent(false))
            {
                JsonObject message = new JsonObject();
                message.Add("method", JsonValue.CreateStringValue("core.library.search"));

                JsonObject queryObject = new JsonObject();
                queryObject.Add("track_name", JsonValue.CreateStringValue(search));

                JsonArray urisArray = new JsonArray();
                urisArray.Add(JsonValue.CreateStringValue("spotify:"));

                JsonObject paramsObject = new JsonObject();
                paramsObject.Add("query", queryObject);
                paramsObject.Add("uris", urisArray);

                message.Add("params", paramsObject);

                string result = null;
                await Send(message, searchResult =>
                {
                    JsonArray tracks = searchResult.GetNamedArray("result")[0].GetObject().GetNamedArray("tracks");
                    result = tracks.First().GetObject().GetNamedString("uri");

                    handle.Set();
                });

                handle.WaitOne(TimeSpan.FromSeconds(30));
                return result;
            }
        }
开发者ID:eerhardt,项目名称:SpotifyVoice,代码行数:32,代码来源:MopidyClient.cs

示例8: SerializeArray

        /// <summary>
        /// 序列化JSONArray对象
        /// </summary>
        /// <param name="jsonArray"></param>
        /// <returns></returns>
        public static string SerializeArray(JsonArray jsonArray)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("[");
            for (int i = 0; i < jsonArray.Count; i++)
            {
                if (jsonArray[i] is JsonObject)
                {
                    sb.Append(string.Format("{0},", SerializeObject((JsonObject)jsonArray[i])));
                }
                else if (jsonArray[i] is JsonArray)
                {
                    sb.Append(string.Format("{0},", SerializeArray((JsonArray)jsonArray[i])));
                }
                else if (jsonArray[i] is String)
                {
                    sb.Append(string.Format("\"{0}\",", jsonArray[i]));
                }
                else
                {
                    sb.Append(string.Format("\"{0}\",", ""));
                }

            }
            if (sb.Length > 1)
                sb.Remove(sb.Length - 1, 1);
            sb.Append("]");
            return sb.ToString();
        }
开发者ID:erpframework,项目名称:spiderframework,代码行数:34,代码来源:JsonConvert.cs

示例9: GetCategoryInfo

 public void GetCategoryInfo(HttpContext context)
 {
     Func<Maticsoft.Model.SNS.Categories, bool> predicate = null;
     string categoryId = context.Request.Params["CID"];
     int type = Globals.SafeInt(context.Request.Params["Type"], 0);
     JsonObject obj2 = new JsonObject();
     if (!string.IsNullOrWhiteSpace(categoryId))
     {
         if (predicate == null)
         {
             predicate = c => c.ParentID == Globals.SafeInt(categoryId, 0);
         }
         List<Maticsoft.Model.SNS.Categories> list2 = this.SNSCateBll.GetAllCateByCache(type).Where<Maticsoft.Model.SNS.Categories>(predicate).ToList<Maticsoft.Model.SNS.Categories>();
         if ((list2 != null) && (list2.Count > 0))
         {
             JsonArray data = new JsonArray();
             list2.ForEach(delegate (Maticsoft.Model.SNS.Categories info) {
                 data.Add(new JsonObject(new string[] { "CategoryId", "Name", "ParentID", "HasChildren" }, new object[] { info.CategoryId, info.Name, info.ParentID, info.HasChildren }));
             });
             obj2.Put("STATUS", "Success");
             obj2.Put("DATA", data);
         }
         else
         {
             obj2.Put("STATUS", "Fail");
         }
     }
     else
     {
         obj2.Put("STATUS", "Error");
     }
     context.Response.Write(obj2.ToString());
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:33,代码来源:CategoriesHandler.cs

示例10: Stringify

        public string Stringify()
        {
            JsonArray jsonArray = new JsonArray();
            foreach (School school in Education)
            {
                jsonArray.Add(school.ToJsonObject());
            }

            JsonObject jsonObject = new JsonObject();
            jsonObject[idKey] = JsonValue.CreateStringValue(Id);

            // Treating a blank string as null
            if (String.IsNullOrEmpty(Phone))
            {
                jsonObject[phoneKey] = JsonValue.CreateNullValue();
            }
            else
            {
                jsonObject[phoneKey] = JsonValue.CreateStringValue(Phone);
            }

            jsonObject[nameKey] = JsonValue.CreateStringValue(Name);
            jsonObject[educationKey] = jsonArray;
            jsonObject[timezoneKey] = JsonValue.CreateNumberValue(Timezone);
            jsonObject[verifiedKey] = JsonValue.CreateBooleanValue(Verified);

            return jsonObject.Stringify();
        }
开发者ID:RasmusTG,项目名称:Windows-universal-samples,代码行数:28,代码来源:User.cs

示例11: CreateJsonTest

    private void CreateJsonTest()
    {
        JsonArray weekDiet = new JsonArray();
        for(int i=0;i<7;i++)
        {
            JsonObject diet = new JsonObject();
            diet["DayNumber"] = i;
            diet["Breakfast"] = "Banana"+ i;
            diet["Lunch"] = "Banana"+ i;
            diet["Dinner"] = "Banana"+ i;
            diet["WithSugar"] = (i % 2 == 0);
            diet["RandomNumber"] = Random.Range(0f,1.5f);

            weekDiet.Add(diet);
        }

        for (int i=0;i<7;i++)
        {
            if (i % 2 == 1)
            {
                weekDiet[i]["RandomNumber"] = 3;
                weekDiet[i]["RandomNumber"] = weekDiet[i]["RandomNumber"] * 2f;
            }
        }

        Debug.Log("Test InputOutputFileTest done: \n"+ weekDiet.ToJsonPrettyPrintString());
    }
开发者ID:Raysangar,项目名称:NiceJson,代码行数:27,代码来源:JsonTest.cs

示例12: ToJson

        public static JsonObject ToJson(Dominion.GameDescription gameDescription, int starRating)
        {
            JsonObject root = new Windows.Data.Json.JsonObject();

            root.Add(jsonNameDeck, ToJson(gameDescription));

            JsonArray expansionArray = new JsonArray();
            Dominion.Expansion[] presentExpansions;
            Dominion.Expansion[] missingExpansions;
            gameDescription.GetRequiredExpansions(out presentExpansions, out missingExpansions);

            foreach (var expansion in presentExpansions)
            {
                JsonObject expansionObject = new JsonObject();
                expansionObject.Add("name", JsonValue.CreateStringValue(expansion.ToProgramaticName()));
                expansionObject.Add("present", JsonValue.CreateBooleanValue(true));
                expansionArray.Add(expansionObject);
            }

            foreach (var expansion in missingExpansions)
            {
                JsonObject expansionObject = new JsonObject();
                expansionObject.Add("name", JsonValue.CreateStringValue(expansion.ToProgramaticName()));
                expansionObject.Add("present", JsonValue.CreateBooleanValue(false));
                expansionArray.Add(expansionObject);
            }

            root.Add(jsonNameRequiredExpansions, expansionArray);

            root.Add(jsonNameRating, JsonValue.CreateNumberValue(starRating));

            return root;
        }
开发者ID:NathanTeeuwen,项目名称:Dominulator,代码行数:33,代码来源:GameDescriptionParser.cs

示例13: Start

	// Use this for initialization
	void Start ()
    {
        // json对象构造示例
        JsonObject root = new JsonObject();                                              
        root["age"] = 25;
        root["name"] = "rare";
        JsonObject obj = new JsonObject();
        root["person"] = obj;
        obj["age"] = 1;
        obj["name"] = "even";
        JsonArray arr = new JsonArray();
        arr[0] = "ComputerGrphic";
        arr[1] = "Unity3D";
        arr[2] = "Graphic";
        root["books"] = arr;

        // json取值
        int a = root["age"];
        Debug.Log("age:"+a.ToString());
        string v = root["name"];
        Debug.Log("name:" + v);

        // save json and format
        string strSerializeFile = Application.dataPath + "json/home.json";
        RareJson.Serialize(root, strSerializeFile, true);

        // json解析
        string strJsonName = Application.dataPath + "json/Contents.json";
        JsonNode node = RareJson.ParseJsonFile(strJsonName);

        // json not format
        strSerializeFile = Application.dataPath + "json/serialize.json";
        RareJson.Serialize(node, strSerializeFile, false);
	}
开发者ID:gameview,项目名称:RareJson,代码行数:35,代码来源:TestJson.cs

示例14: Visit

 /// <summary>
 /// Visits a json array.
 /// </summary>
 /// <param name="jsonArray">The json array being visited.</param>
 public void Visit(JsonArray jsonArray)
 {
     ExceptionUtilities.CheckArgumentNotNull(jsonArray, "jsonArray");
     this.writer.StartArrayScope();
     jsonArray.Elements.ForEach(e => e.Accept(this));
     this.writer.EndScope();
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:11,代码来源:JsonValueWriter.cs

示例15: Parse

 public static TwitterCoordinates Parse(JsonArray array) {
     if (array == null) return null;
     return new TwitterCoordinates {
         Latitude = array.GetDouble(1),
         Longitude = array.GetDouble(0)
     };
 }
开发者ID:jesperordrup,项目名称:Skybrud.Social,代码行数:7,代码来源:TwitterCoordinates.cs


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