Пример #1
0
        static void DeserializarSubCategorias(string json)
        {
            subCategorias = null;
            subCategorias = new List <SubCategoria>();
            int    _parentId   = 0;
            string _id         = string.Empty;
            string _name       = string.Empty;
            string _isOnline   = string.Empty;
            string valor       = string.Empty;
            string textoOrigen = string.Empty;

            string[] res = null;
            string[] parseSubCategorias = json.Split(new string[] { "subCategories" }, StringSplitOptions.None);
            for (int i = 0; i < parseSubCategorias.Length; i++)
            {
                textoOrigen = parseSubCategorias[i];

                //Obtener parentId
                res = textoOrigen.Split(new string[] { "parentId" }, StringSplitOptions.None);
                if (res.Length > 0)
                {
                    valor = res[res.Length - 1].Replace(",", string.Empty).Replace("\"", string.Empty).Replace(":", string.Empty);
                    int.TryParse(valor, out _parentId);
                }
                else
                {
                    _parentId = 0;
                }

                if (_parentId != 0)
                {
                    //Obtener id
                    textoOrigen = parseSubCategorias[i].Replace("\"$id\"", string.Empty);
                    res         = textoOrigen.Split(new string[] { "id" }, StringSplitOptions.None);
                    if (res.Length > 0)
                    {
                        _id = res[res.Length - 1].Split(',')[0].Replace(":", string.Empty).Replace("\"", string.Empty);
                    }
                    else
                    {
                        _id = string.Empty;
                    }

                    //Obtener nombre
                    res = textoOrigen.Split(new string[] { "name" }, StringSplitOptions.None);
                    if (res.Length > 0)
                    {
                        _name = res[res.Length - 1].Split(',')[0].Replace(":", string.Empty).Replace("\"", string.Empty);
                    }
                    else
                    {
                        _name = string.Empty;
                    }

                    //Obtener isOnline
                    res = textoOrigen.Split(new string[] { "isOnline" }, StringSplitOptions.None);
                    if (res.Length > 0)
                    {
                        _isOnline = res[res.Length - 1].Split(',')[0].Replace(":", string.Empty).Replace("\"", string.Empty);
                    }
                    else
                    {
                        _isOnline = string.Empty;
                    }
                }
                if (_parentId != 0 && !(string.IsNullOrEmpty(_parentId.ToString())))
                {
                    SubCategoria sc = new SubCategoria();
                    sc.id       = _id;
                    sc.name     = _name;
                    sc.parentId = _parentId.ToString();
                    sc.isOnline = _isOnline;
                    subCategorias.Add(sc);
                    sc = null;
                }
            }
        }
 public bool CamilyoguardarInfoSubCategorias(SubCategoria subCategoria)
 {
     return(objCategorias.CamilyoguardarInfoSubCategoria(subCategoria));
 }