예제 #1
0
        // <array> = [<value>,<value>,…]
        // 上位レベルで'['が出たらこれに放りこむ
        // ']'が出たらARRAYを閉じる
        private static classJSONArray getJSONArray(string json, ref int index)
        {
            classJSONArray result = new classJSONArray();
            classJSONValue value = null;
            char charData;
            bool isEnd = false;

            // 初めの文字は'['であることが必須
            if (json[index] != '[')
            {
                return null;
            }
            index++;

            while (!isEnd && json.Length > index)
            {
                charData = json[index];
                switch (charData)
                {
                    case '\n':  //空白類文字は無視
                    case '\r':
                    case '\t':
                    case ' ':
                        index++;
                        break;
                    case ']':   // ARRAYの終わり
                        isEnd = true;
                        index++;
                        break;
                    case '{':   // OBJECT START
                    case '\"':  // PAIRの始まり
                        value = getJSONValue(json, ref index);
                        if(value != null)
                        {
                            result.add(value);
                        }
                        break;
                    case ',':
                        index++;
                        value = getJSONValue(json, ref index);
                        if(value != null)
                        {
                            result.add(value);
                        }
                        break;
                    default:
                        if (Char.IsDigit(charData))
                        {
                            //  数値
                            value = getJSONValue(json, ref index);
                            if (value != null)
                            {
                                result.add(value);
                            }
                        }
                        else
                        {
                            // エラー
                            isEnd = true;
                        }
                        break;
                }
            }
            return result;
        }
예제 #2
0
        // <array> = [<value>,<value>,…]
        // 上位レベルで'['が出たらこれに放りこむ
        // ']'が出たらARRAYを閉じる
        private static classJSONArray getJSONArray(string json, ref int index)
        {
            classJSONArray result = new classJSONArray();
            classJSONValue value  = null;
            char           charData;
            bool           isEnd = false;

            // 初めの文字は'['であることが必須
            if (json[index] != '[')
            {
                return(null);
            }
            index++;

            while (!isEnd && json.Length > index)
            {
                charData = json[index];
                switch (charData)
                {
                case '\n':      //空白類文字は無視
                case '\r':
                case '\t':
                case ' ':
                    index++;
                    break;

                case ']':       // ARRAYの終わり
                    isEnd = true;
                    index++;
                    break;

                case '{':       // OBJECT START
                case '\"':      // PAIRの始まり
                    value = getJSONValue(json, ref index);
                    if (value != null)
                    {
                        result.add(value);
                    }
                    break;

                case ',':
                    index++;
                    value = getJSONValue(json, ref index);
                    if (value != null)
                    {
                        result.add(value);
                    }
                    break;

                default:
                    if (Char.IsDigit(charData))
                    {
                        //  数値
                        value = getJSONValue(json, ref index);
                        if (value != null)
                        {
                            result.add(value);
                        }
                    }
                    else
                    {
                        // エラー
                        isEnd = true;
                    }
                    break;
                }
            }
            return(result);
        }