using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
namespace FastJSON
{
///
/// This class encodes and decodes JSON strings.
/// Spec. details, see http://www.json.org/
///
internal sealed class JsonParser
{
enum Token
{
None = -1, // Used to denote no Lookahead available
Curly_Open,
Curly_Close,
Squared_Open,
Squared_Close,
Colon,
Comma,
String,
Number,
True,
False,
Null
}
readonly string json;
readonly StringBuilder s = new StringBuilder();
Token lookAheadToken = Token.None;
int index;
internal JsonParser(string json)
{
this.json = json;
}
public object Decode()
{
return ParseValue();
}
private Dictionary ParseObject()
{
Dictionary table = new Dictionary();
ConsumeToken(); // {
while (true)
{
switch (LookAhead())
{
case Token.Comma:
ConsumeToken();
break;
case Token.Curly_Close:
ConsumeToken();
return table;
default:
{
// name
string name = ParseString();
// :
if (NextToken() != Token.Colon)
{
throw new Exception("Expected colon at index " + index);
}
// value
object value = ParseValue();
table[name] = value;
}
break;
}
}
}
private List