Ejemplo n.º 1
0
 public override TypeHandler Serialize(Vector input)
 {
     this["data"] = new JsonList {
         input.X, input.Y, input.Z
     };
     return(this);
 }
Ejemplo n.º 2
0
 public override TypeHandler Serialize(Direction input)
 {
     this["data"] = new JsonList {
         input.Euler.x, input.Euler.y, input.Euler.z
     };
     return(this);
 }
Ejemplo n.º 3
0
 public void PutIt(OpenTidlSession session, JsonList <JsonListItem <ArtistModel> > itemsToPut)
 {
     foreach (var itemToPut in itemsToPut.Items)
     {
         session.AddFavoriteArtist(itemToPut.Item.Id);
     }
 }
Ejemplo n.º 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));
            }
        }
Ejemplo n.º 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 =
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
    }
Ejemplo n.º 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);
        }
    }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
                }
            }
        }
Ejemplo n.º 11
0
        public bool TryGet(string name, out VariableSet variableSet)
        {
            var result = JsonList.TryGetValue(name, out var json);

            variableSet = result ? CreateSet(json) : null;
            return(result);
        }
Ejemplo n.º 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);
            }
Ejemplo n.º 13
0
 public void PutIt(OpenTidlSession session, JsonList <PlaylistModel> itemsToPut)
 {
     foreach (var itemToPut in itemsToPut.Items)
     {
         session.AddFavoritePlaylist(itemToPut.Uuid);
     }
 }
Ejemplo n.º 14
0
        /// <summary>
        /// 将数据存储
        /// </summary>
        public static void Store()
        {
            var keyJson = new JsonList <string>(Keys).ToJson();

            PlayerPrefs.SetString(DataSetKey, keyJson);
            PlayerPrefs.Save();
        }
Ejemplo n.º 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);
    }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
    }
Ejemplo n.º 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));
                }
            }
        }
Ejemplo n.º 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);
    }
Ejemplo n.º 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());
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
    }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
    }
Ejemplo n.º 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 =
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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));
 }