Exemple #1
0
        public static string[] getKeyValue(string json)
        {
            List <string> dataList = new List <string>();
            bool          inString = false;
            string        key      = json;
            string        value    = "";

            for (int i = 0; i < json.Length; i++)
            {
                char c = json[i];
                if (c == '\\')   // skip escaped character
                {
                    i++;
                    continue;
                }
                if (!inString)
                {
                    if (c == '"')   // entering string
                    {
                        inString = true;
                        continue;
                    }
                    if (c == ':')
                    {
                        key   = json.Substring(0, i);
                        value = json.Substring(i + 1);
                        break;
                    }
                }
                else
                {
                    if (c == '"')   // leaving string
                    {
                        inString = false;
                        continue;
                    }
                }
            }
            key   = StringParsingTool.cleanString(key);
            value = StringParsingTool.cleanString(value);
            dataList.Add(key);
            dataList.Add(value);
            return(dataList.ToArray());
        }
Exemple #2
0
 public ArrayJSON(string json)
 {
     originalJSON = StringParsingTool.getBetweenSquareBracket(json);
     string[] elements = ParserJSON.getDataList(originalJSON);
     data = new object[elements.Length];
     for (int i = 0; i < elements.Length; i++)
     {
         string value = elements[i];
         if (ParserJSON.isStringObjectJSON(value))
         {
             data[i] = new ObjectJSON(value);
         }
         else if (ParserJSON.isStringArrayJSON(value))
         {
             data[i] = new ArrayJSON(value);
         }
         else
         {
             data[i] = StringParsingTool.cleanString(value);
         }
     }
 }
Exemple #3
0
        public ObjectJSON(string json)
        {
            originalJSON = StringParsingTool.getBetweenCurlyBracket(json);
            Dictionary <string, string> elements = ParserJSON.getDataDictionnary(originalJSON);

            data = new Dictionary <string, object>();
            foreach (string key in elements.Keys)
            {
                string value = elements[key];
                if (ParserJSON.isStringObjectJSON(value))
                {
                    data[key] = new ObjectJSON(value);
                }
                else if (ParserJSON.isStringArrayJSON(value))
                {
                    data[key] = new ArrayJSON(value);
                }
                else
                {
                    data[key] = StringParsingTool.cleanString(value);
                }
            }
        }