Exemple #1
0
 public override TypeHandler Serialize(Vector input)
 {
     this["data"] = new JsonList {
         input.X, input.Y, input.Z
     };
     return(this);
 }
Exemple #2
0
 public override TypeHandler Serialize(Direction input)
 {
     this["data"] = new JsonList {
         input.Euler.x, input.Euler.y, input.Euler.z
     };
     return(this);
 }
Exemple #3
0
 public void PutIt(OpenTidlSession session, JsonList <JsonListItem <ArtistModel> > itemsToPut)
 {
     foreach (var itemToPut in itemsToPut.Items)
     {
         session.AddFavoriteArtist(itemToPut.Item.Id);
     }
 }
Exemple #4
0
        public object this[string key]
        {
            get
            {
                object obj  = jobject[key];
                JArray list = obj as JArray;
                if (list != null)
                {
                    var query = from jobj in list select new JsonValue(jobj.GetType() == typeof(JObject) ? (JObject)jobj : new JObject(jobj));
                    var jlist = new JsonList();
                    jlist.AddRange(query);
                    return(jlist);
                }

                JObject jo = obj as JObject;
                if (jo != null)
                {
                    return(new JsonValue(jo));
                }

                return((string)jobject[key]);
            }
            set
            {
                if (jobject[key] != null)
                {
                    jobject.Remove(key);
                    Properties.Remove(key);
                }
                jobject.Add(new JProperty(key, value));
            }
        }
Exemple #5
0
        public static void JsonList_ToList()
        {
            JsonList <UserBase> sl = new JsonList <UserBase>("json_list");

            sl.Clear();
            UserBase[] values = new UserBase[] {
                new UserBase {
                    Name = "a"
                },
                new UserBase {
                    Name = "b"
                },
                new UserBase {
                    Name = "c"
                },
                new UserBase {
                    Name = "D"
                }
            };

            foreach (UserBase item in values)
            {
                sl.Add(item);
            }


            //IList<UserBase> result =
        }
Exemple #6
0
 ///-------------------------------------------------------------------------------------------------
 /// <summary>  接收消息回调 </summary>
 ///
 /// <remarks>   Administrator, 2015/5/21. </remarks>
 ///
 /// <param name="data"> The data. </param>
 ///-------------------------------------------------------------------------------------------------
 private static void OnActionHandle(Message data)
 {
     lock (JsonList)
     {
         JsonList.Add(data);
     }
 }
Exemple #7
0
    void SaveOwnProduct(List <Product> productList)
    {
        JsonList <string> productJsonList = new JsonList <string>();

        productList.ForEach((obj) => productJsonList.list.Add(obj.id));
        Files.SaveFile("ownProduct.json", productJsonList);
    }
Exemple #8
0
    public void OnRequestClasses(JsonRequest requested)
    {
        if (requested.success == "true")
        {
            JsonList contentList = JsonUtility.FromJson <JsonList>(requested.content);

            List <Dropdown.OptionData> optionsClasses = new List <Dropdown.OptionData>();
            for (int i = 0; i < contentList.classes.Count; i++)
            {
                optionsClasses.Add(new Dropdown.OptionData(contentList.classes[i].Class));
            }
            dropClasses.AddOptions(optionsClasses);

            List <Dropdown.OptionData> optionsRaces = new List <Dropdown.OptionData>();
            for (int i = 0; i < contentList.races.Count; i++)
            {
                optionsRaces.Add(new Dropdown.OptionData(contentList.races[i].Race));
            }
            dropRaces.AddOptions(optionsRaces);
        }
        else
        {
            Debug.LogError(requested.error);
        }
    }
Exemple #9
0
        public override TypeHandler Serialize(Lexicon input)
        {
            var data   = new JsonDict();
            var keys   = new JsonList();
            var values = new JsonList();

            foreach (var kvp in input.Select(x => new KeyValuePair <object, object>(serializer.Serialize(x.Key), serializer.Serialize(x.Value))))
            {
                if (kvp.Key is string)
                {
                    data[(string)kvp.Key] = kvp.Value;
                }
                else
                {
                    keys.Add(kvp.Key);
                    values.Add(kvp.Value);
                }
            }
            this["data"]   = data;
            this["keys"]   = keys;
            this["values"] = values;
            if ((BooleanValue)input.GetSuffix("CASESENSITIVE").Value)
            {
                this["sensitive"] = true;
            }
            else
            {
                this.Remove("sensitive");
            }
            return(this);
        }
Exemple #10
0
        public JsonValue(JObject obj)
        {
            jobject = obj;
            foreach (var token in obj)
            {
                switch (token.Value.Type)
                {
                case JTokenType.Object:
                    Properties[token.Key] = new JsonValue((JObject)token.Value);
                    break;

                case JTokenType.Array:
                    JArray list  = token.Value as JArray;
                    var    query = from jobj in list select new JsonValue(jobj.GetType() == typeof(JObject) ? (JObject)jobj : new JObject(jobj));
                    var    jlist = new JsonList();
                    jlist.AddRange(query);
                    break;

                case JTokenType.Null:
                    Properties[token.Key] = null;
                    break;

                default:
                    Properties[token.Key] = token.Value.ToString();
                    break;
                }
            }
        }
        public bool TryGet(string name, out VariableSet variableSet)
        {
            var result = JsonList.TryGetValue(name, out var json);

            variableSet = result ? CreateSet(json) : null;
            return(result);
        }
Exemple #12
0
            private static JsonList loadList(string jsonStr, ref int i)
            {
                JsonList list = new JsonList();

                ++i;

                while (true)
                {
                    while (char.IsWhiteSpace(jsonStr[i]) || jsonStr[i] == ',')
                    {
                        ++i;
                    }

                    if (jsonStr[i] == ']')
                    {
                        break;
                    }

                    list.Add(load(jsonStr, ref i));
                }

                ++i;

                return(list);
            }
Exemple #13
0
 public void PutIt(OpenTidlSession session, JsonList <PlaylistModel> itemsToPut)
 {
     foreach (var itemToPut in itemsToPut.Items)
     {
         session.AddFavoritePlaylist(itemToPut.Uuid);
     }
 }
Exemple #14
0
        /// <summary>
        /// 将数据存储
        /// </summary>
        public static void Store()
        {
            var keyJson = new JsonList <string>(Keys).ToJson();

            PlayerPrefs.SetString(DataSetKey, keyJson);
            PlayerPrefs.Save();
        }
Exemple #15
0
    void SaveOwnTips(List <Tips> tipsList)
    {
        JsonList <int> tipsJsonList = new JsonList <int>();

        tipsList.ForEach((tips) => tipsJsonList.list.Add(tips.id));
        Files.SaveFile("ownTips.json", tipsJsonList);
    }
Exemple #16
0
        public static List <T> ListFromFile <T>(string name)
        {
            TextAsset    json       = ResManager.Get().Load <TextAsset>(name);
            JsonList <T> jsonObject = JsonUtility.FromJson <JsonList <T> >(json.text);

            return(jsonObject.jsonList);
        }
Exemple #17
0
    void SaveUnlockLevel(List <Level> levelList)
    {
        JsonList <int> levelJsonList = new JsonList <int>();

        levelList.ForEach((level) => levelJsonList.list.Add(level.id));
        Files.SaveFile("unlockLevel.json", levelJsonList);
    }
Exemple #18
0
        public JsonResult SortRecords(string list)
        {
            JsonList psl = (new JavaScriptSerializer()).Deserialize <JsonList>(list);

            string[] idsList = psl.list;
            using (MainContext db = new MainContext())
            {
                try
                {
                    int row = 0;
                    foreach (string id in idsList)
                    {
                        int     mid           = Convert.ToInt32(id);
                        Product sortingrecord = db.Product.SingleOrDefault(d => d.ProductId == mid);
                        sortingrecord.SortNumber = Convert.ToInt32(row);
                        db.SaveChanges();
                        row++;
                    }
                    return(Json(true));
                }
                catch (Exception)
                {
                    return(Json(false));
                }
            }
        }
Exemple #19
0
    void SaveOwnProps(List <Props> propsList)
    {
        JsonList <int> propsJosnList = new JsonList <int>();

        propsList.ForEach((obj) => propsJosnList.list.Add(obj.id));
        Files.SaveFile("ownProps.json", propsJosnList);
    }
Exemple #20
0
        public void OnToStringString()
        {
            var jsonList = new JsonList();

            jsonList.Add(new JsonString("value 1"), new JsonString("value 2"));

            Assert.AreEqual("[\"value 1\", \"value 2\"]", jsonList.ToString());
        }
Exemple #21
0
        private void assertListParseFail(string json)
        {
            Assert.Throws <JsonParseException>(() => JsonList.Parse(json));
            JsonList val;

            Assert.IsFalse(JsonList.TryParse(json, out val));
            Assert.IsNull(val);
        }
Exemple #22
0
        public void OnToStringLong()
        {
            var jsonList = new JsonList();

            jsonList.Add(new JsonLong(1), new JsonLong(2), new JsonLong(3));

            Assert.AreEqual("[1, 2, 3]", jsonList.ToString());
        }
Exemple #23
0
        private void assertListParseSucc(string json, JsonList expected)
        {
            JsonList t = null;

            Assert.DoesNotThrow(() => { t = JsonList.Parse(json); });
            Assert.IsTrue(expected.Equals(t));
            Assert.IsTrue(JsonList.TryParse(json, out t));
            Assert.IsTrue(expected.Equals(t));
        }
Exemple #24
0
        public JsonResult SortRecords(string list)
        {
            JsonList psl = (new JavaScriptSerializer()).Deserialize <JsonList>(list);

            string[] idsList  = psl.list;
            bool     issorted = NewsManager.SortRecords(idsList);

            return(Json(issorted));
        }
Exemple #25
0
        private static object convertList(JsonList list, SucoType elementType)
        {
            var result = elementType.CreateArray(list.Count);

            for (var i = 0; i < list.Count; i++)
            {
                result.SetValue(convertVariableValue(elementType, list[i]), i);
            }
            return(result);
        }
Exemple #26
0
        //Get All days of personal resovations
        public JObject GetPersonalReservations(string userId)
        {
            var days        = _dbAgenda.GetReservations(userId);
            var setJsonList = new JsonList();

            setJsonList.random = days;
            var sendBack = _jsonEditor.SerilizeJObject(setJsonList);

            return(sendBack);
        }
Exemple #27
0
    public static void SaveGeneData(Gene[] population)
    {
        JsonList geneJson = new JsonList();

        geneJson.geneList = population;
        string dataAsJson = JsonUtility.ToJson(geneJson);

        string filePath = Path.Combine(Application.streamingAssetsPath, gameDataFileName);

        File.WriteAllText(filePath, dataAsJson);
    }
Exemple #28
0
        public void OnAddList()
        {
            var jsonList = new JsonList();

            jsonList.Add(new JsonLong(1), new JsonLong(2), new JsonLong(3));

            Assert.AreEqual(1, int.Parse(jsonList[0].ToString()));
            Assert.AreEqual(2, int.Parse(jsonList[1].ToString()));
            Assert.AreEqual(3, int.Parse(jsonList[2].ToString()));
            Assert.AreEqual(3, (jsonList.GetValue() as List <Json>).Count);
        }
Exemple #29
0
        public void OnEquals_PrimitiveTypes()
        {
            var jsonList1 = new JsonList();

            jsonList1.Add(new JsonLong(1), new JsonLong(2), new JsonLong(3));

            var jsonList2 = new JsonList();

            jsonList2.Add(new JsonLong(1), new JsonLong(2), new JsonLong(3));

            Assert.IsTrue(jsonList1.Equals(jsonList2));
        }
Exemple #30
0
    List <T> LoadListFromJson <T>(string jsonName)
    {
        List <T>     returnList = new List <T>();
        JsonList <T> jsonList   = new JsonList <T>();

        jsonList = Files.LoadFile <JsonList <T> >(jsonName);
        if (jsonList != null)
        {
            jsonList.list.ForEach((obj) => returnList.Add(obj));
        }
        return(returnList);
    }
Exemple #31
0
        public static void JsonList_ToList()
        {
            JsonList<UserBase> sl = new JsonList<UserBase>("json_list");
            sl.Clear();
            UserBase[] values = new UserBase[] {
                new UserBase{ Name="a" },
                new UserBase { Name="b" },
                new UserBase { Name="c" },
                new UserBase { Name ="D" }
            };

            foreach (UserBase item in values)
            {
                sl.Add(item);
            }

            //IList<UserBase> result =
        }
Exemple #32
0
        private static bool GetAzyobuziApiResult(string uri, out string resultUri)
        {
            const string apiBaseUri = @"http://img.azyobuzi.net/api/all_sizes.json?uri=";

            var req = WebRequest.Create(apiBaseUri + uri);
            req.Timeout = 3000;

            try
            {
                var res = (HttpWebResponse) req.GetResponse();
                if (res.StatusCode == HttpStatusCode.OK)
                {
                    using (var resStream = res.GetResponseStream())
                    {
                        if (resStream != null)
                        {
                            using (var sr = new StreamReader(resStream, Encoding.UTF8))
                            {
                                var resBody = sr.ReadToEnd();
                                var resJson = new JsonList(resBody);
                                resultUri =
                                    resJson.Where(x => x.Name.Contains(@"full")).Where(x => x.Value != null).ToList()[0]
                                        ?
                                        .Value
                                        .ToString();
                                return true;
                            }
                        }
                    }
                }
                resultUri = null;
                return false;
            }
            catch
            {
                resultUri = null;
                return false;
            }
        }
Exemple #33
0
        private static bool IsGyazoPhoto(string uri, out string resultUri)
        {
            const string apiBaseUri = @"https://api.gyazo.com/api/oembed/?url=";

            resultUri = null;
            var regex = new Regex(@"(?<baseUri>http(s)?://gyazo.com/)(?<imageId>.*)");
            if (regex.IsMatch(uri))
            {
                var req = WebRequest.Create(apiBaseUri + uri);
                req.Timeout = 3000;

                try
                {
                    var res = (HttpWebResponse) req.GetResponse();
                    if (res.StatusCode == HttpStatusCode.OK)
                    {
                        using (var resStream = res.GetResponseStream())
                        {
                            if (resStream != null)
                            {
                                using (var sr = new StreamReader(resStream, Encoding.UTF8))
                                {
                                    var resBody = sr.ReadToEnd();
                                    var resJson = new JsonList(resBody);
                                    resultUri =
                                        resJson.Where(x => x.Name == "url").Where(x => x.Value != null).ToList()[0]?
                                            .Value
                                            .ToString();
                                    return true;
                                }
                            }
                        }
                    }
                    return false;
                }
                catch
                {
                    resultUri = null;
                    return false;
                }
            }

            return false;
        }
Exemple #34
0
 private void assertListParseSucc(string json, JsonList expected)
 {
     JsonList t = null;
     Assert.DoesNotThrow(() => { t = JsonList.Parse(json); });
     Assert.IsTrue(expected.Equals(t));
     Assert.IsTrue(JsonList.TryParse(json, out t));
     Assert.IsTrue(expected.Equals(t));
 }