コード例 #1
0
        /// <summary>
        /// i can find the value you need in the json (if the math value over one it will spit with ",")
        /// </summary>
        /// <param name="yourTarget">the key you want get</param>
        /// <param name="yourSouce">the json Souce</param>
        /// <returns>back value</returns>
        public static string[] PickJsonParameter(string yourTarget, string yourSouce)
        {
            string tempTarget = "\"" + yourTarget + "\"";

            string[] myJsonBackAr = null;
            string[] myJsonBack   = null;
            if (!yourSouce.Contains(tempTarget))
            {
                return(null);
            }
            try
            {
                yourSouce = yourSouce.Trim();
                if (yourSouce.StartsWith("["))
                {
                    JArray jAObj = (JArray)JsonConvert.DeserializeObject(yourSouce);
                    for (int i = 0; i < jAObj.Count; i++)
                    {
                        JObject jObj = (JObject)jAObj[i];
                        myJsonBackAr = GetJTokenValueEx(jObj, yourTarget);
                        if (myJsonBackAr != null)
                        {
                            myJsonBack = StringHelper.AddStringArr(myJsonBack, myJsonBackAr);
                        }
                    }
                }
                else if (yourSouce.StartsWith("{"))
                {
                    JObject jObj = (JObject)JsonConvert.DeserializeObject(yourSouce);
                    myJsonBackAr = GetJTokenValueEx(jObj, yourTarget);
                    myJsonBack   = myJsonBackAr;
                }
            }
            catch (Exception ex)
            {
                ErrorLog.PutInLog("ID:0243 " + ex.Message);
            }
            return(myJsonBack);
        }