|
@@ -19,7 +19,7 @@ using System.Collections.Generic;
|
|
/// </summary>
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
-public class ShareMiniJSON
|
|
|
|
|
|
+public class MiniJSON
|
|
{
|
|
{
|
|
private const int TOKEN_NONE = 0;
|
|
private const int TOKEN_NONE = 0;
|
|
private const int TOKEN_CURLY_OPEN = 1;
|
|
private const int TOKEN_CURLY_OPEN = 1;
|
|
@@ -50,19 +50,19 @@ public class ShareMiniJSON
|
|
public static object jsonDecode( string json )
|
|
public static object jsonDecode( string json )
|
|
{
|
|
{
|
|
// save the string for debug information
|
|
// save the string for debug information
|
|
- ShareMiniJSON.lastDecode = json;
|
|
|
|
|
|
+ MiniJSON.lastDecode = json;
|
|
|
|
|
|
if( json != null )
|
|
if( json != null )
|
|
{
|
|
{
|
|
char[] charArray = json.ToCharArray();
|
|
char[] charArray = json.ToCharArray();
|
|
int index = 0;
|
|
int index = 0;
|
|
bool success = true;
|
|
bool success = true;
|
|
- object value = ShareMiniJSON.parseValue( charArray, ref index, ref success );
|
|
|
|
|
|
+ object value = MiniJSON.parseValue( charArray, ref index, ref success );
|
|
|
|
|
|
if( success )
|
|
if( success )
|
|
- ShareMiniJSON.lastErrorIndex = -1;
|
|
|
|
|
|
+ MiniJSON.lastErrorIndex = -1;
|
|
else
|
|
else
|
|
- ShareMiniJSON.lastErrorIndex = index;
|
|
|
|
|
|
+ MiniJSON.lastErrorIndex = index;
|
|
|
|
|
|
return value;
|
|
return value;
|
|
}
|
|
}
|
|
@@ -81,7 +81,7 @@ public class ShareMiniJSON
|
|
public static string jsonEncode( object json )
|
|
public static string jsonEncode( object json )
|
|
{
|
|
{
|
|
var builder = new StringBuilder( BUILDER_CAPACITY );
|
|
var builder = new StringBuilder( BUILDER_CAPACITY );
|
|
- var success = ShareMiniJSON.serializeValue( json, builder );
|
|
|
|
|
|
+ var success = MiniJSON.serializeValue( json, builder );
|
|
|
|
|
|
return ( success ? builder.ToString() : null );
|
|
return ( success ? builder.ToString() : null );
|
|
}
|
|
}
|
|
@@ -93,7 +93,7 @@ public class ShareMiniJSON
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
public static bool lastDecodeSuccessful()
|
|
public static bool lastDecodeSuccessful()
|
|
{
|
|
{
|
|
- return ( ShareMiniJSON.lastErrorIndex == -1 );
|
|
|
|
|
|
+ return ( MiniJSON.lastErrorIndex == -1 );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -103,7 +103,7 @@ public class ShareMiniJSON
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
public static int getLastErrorIndex()
|
|
public static int getLastErrorIndex()
|
|
{
|
|
{
|
|
- return ShareMiniJSON.lastErrorIndex;
|
|
|
|
|
|
+ return MiniJSON.lastErrorIndex;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -114,21 +114,21 @@ public class ShareMiniJSON
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
public static string getLastErrorSnippet()
|
|
public static string getLastErrorSnippet()
|
|
{
|
|
{
|
|
- if( ShareMiniJSON.lastErrorIndex == -1 )
|
|
|
|
|
|
+ if( MiniJSON.lastErrorIndex == -1 )
|
|
{
|
|
{
|
|
return "";
|
|
return "";
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- int startIndex = ShareMiniJSON.lastErrorIndex - 5;
|
|
|
|
- int endIndex = ShareMiniJSON.lastErrorIndex + 15;
|
|
|
|
|
|
+ int startIndex = MiniJSON.lastErrorIndex - 5;
|
|
|
|
+ int endIndex = MiniJSON.lastErrorIndex + 15;
|
|
if( startIndex < 0 )
|
|
if( startIndex < 0 )
|
|
startIndex = 0;
|
|
startIndex = 0;
|
|
|
|
|
|
- if( endIndex >= ShareMiniJSON.lastDecode.Length )
|
|
|
|
- endIndex = ShareMiniJSON.lastDecode.Length - 1;
|
|
|
|
|
|
+ if( endIndex >= MiniJSON.lastDecode.Length )
|
|
|
|
+ endIndex = MiniJSON.lastDecode.Length - 1;
|
|
|
|
|
|
- return ShareMiniJSON.lastDecode.Substring( startIndex, endIndex - startIndex + 1 );
|
|
|
|
|
|
+ return MiniJSON.lastDecode.Substring( startIndex, endIndex - startIndex + 1 );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -147,15 +147,15 @@ public class ShareMiniJSON
|
|
while( !done )
|
|
while( !done )
|
|
{
|
|
{
|
|
token = lookAhead( json, index );
|
|
token = lookAhead( json, index );
|
|
- if( token == ShareMiniJSON.TOKEN_NONE )
|
|
|
|
|
|
+ if( token == MiniJSON.TOKEN_NONE )
|
|
{
|
|
{
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
- else if( token == ShareMiniJSON.TOKEN_COMMA )
|
|
|
|
|
|
+ else if( token == MiniJSON.TOKEN_COMMA )
|
|
{
|
|
{
|
|
nextToken( json, ref index );
|
|
nextToken( json, ref index );
|
|
}
|
|
}
|
|
- else if( token == ShareMiniJSON.TOKEN_CURLY_CLOSE )
|
|
|
|
|
|
+ else if( token == MiniJSON.TOKEN_CURLY_CLOSE )
|
|
{
|
|
{
|
|
nextToken( json, ref index );
|
|
nextToken( json, ref index );
|
|
return table;
|
|
return table;
|
|
@@ -171,7 +171,7 @@ public class ShareMiniJSON
|
|
|
|
|
|
// :
|
|
// :
|
|
token = nextToken( json, ref index );
|
|
token = nextToken( json, ref index );
|
|
- if( token != ShareMiniJSON.TOKEN_COLON )
|
|
|
|
|
|
+ if( token != MiniJSON.TOKEN_COLON )
|
|
return null;
|
|
return null;
|
|
|
|
|
|
// value
|
|
// value
|
|
@@ -199,15 +199,15 @@ public class ShareMiniJSON
|
|
while( !done )
|
|
while( !done )
|
|
{
|
|
{
|
|
int token = lookAhead( json, index );
|
|
int token = lookAhead( json, index );
|
|
- if( token == ShareMiniJSON.TOKEN_NONE )
|
|
|
|
|
|
+ if( token == MiniJSON.TOKEN_NONE )
|
|
{
|
|
{
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
- else if( token == ShareMiniJSON.TOKEN_COMMA )
|
|
|
|
|
|
+ else if( token == MiniJSON.TOKEN_COMMA )
|
|
{
|
|
{
|
|
nextToken( json, ref index );
|
|
nextToken( json, ref index );
|
|
}
|
|
}
|
|
- else if( token == ShareMiniJSON.TOKEN_SQUARED_CLOSE )
|
|
|
|
|
|
+ else if( token == MiniJSON.TOKEN_SQUARED_CLOSE )
|
|
{
|
|
{
|
|
nextToken( json, ref index );
|
|
nextToken( json, ref index );
|
|
break;
|
|
break;
|
|
@@ -231,24 +231,24 @@ public class ShareMiniJSON
|
|
{
|
|
{
|
|
switch( lookAhead( json, index ) )
|
|
switch( lookAhead( json, index ) )
|
|
{
|
|
{
|
|
- case ShareMiniJSON.TOKEN_STRING:
|
|
|
|
|
|
+ case MiniJSON.TOKEN_STRING:
|
|
return parseString( json, ref index );
|
|
return parseString( json, ref index );
|
|
- case ShareMiniJSON.TOKEN_NUMBER:
|
|
|
|
|
|
+ case MiniJSON.TOKEN_NUMBER:
|
|
return parseNumber( json, ref index );
|
|
return parseNumber( json, ref index );
|
|
- case ShareMiniJSON.TOKEN_CURLY_OPEN:
|
|
|
|
|
|
+ case MiniJSON.TOKEN_CURLY_OPEN:
|
|
return parseObject( json, ref index );
|
|
return parseObject( json, ref index );
|
|
- case ShareMiniJSON.TOKEN_SQUARED_OPEN:
|
|
|
|
|
|
+ case MiniJSON.TOKEN_SQUARED_OPEN:
|
|
return parseArray( json, ref index );
|
|
return parseArray( json, ref index );
|
|
- case ShareMiniJSON.TOKEN_TRUE:
|
|
|
|
|
|
+ case MiniJSON.TOKEN_TRUE:
|
|
nextToken( json, ref index );
|
|
nextToken( json, ref index );
|
|
return Boolean.Parse( "TRUE" );
|
|
return Boolean.Parse( "TRUE" );
|
|
- case ShareMiniJSON.TOKEN_FALSE:
|
|
|
|
|
|
+ case MiniJSON.TOKEN_FALSE:
|
|
nextToken( json, ref index );
|
|
nextToken( json, ref index );
|
|
return Boolean.Parse( "FALSE" );
|
|
return Boolean.Parse( "FALSE" );
|
|
- case ShareMiniJSON.TOKEN_NULL:
|
|
|
|
|
|
+ case MiniJSON.TOKEN_NULL:
|
|
nextToken( json, ref index );
|
|
nextToken( json, ref index );
|
|
return null;
|
|
return null;
|
|
- case ShareMiniJSON.TOKEN_NONE:
|
|
|
|
|
|
+ case MiniJSON.TOKEN_NONE:
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -402,7 +402,7 @@ public class ShareMiniJSON
|
|
|
|
|
|
if( index == json.Length )
|
|
if( index == json.Length )
|
|
{
|
|
{
|
|
- return ShareMiniJSON.TOKEN_NONE;
|
|
|
|
|
|
+ return MiniJSON.TOKEN_NONE;
|
|
}
|
|
}
|
|
|
|
|
|
char c = json[index];
|
|
char c = json[index];
|
|
@@ -410,17 +410,17 @@ public class ShareMiniJSON
|
|
switch( c )
|
|
switch( c )
|
|
{
|
|
{
|
|
case '{':
|
|
case '{':
|
|
- return ShareMiniJSON.TOKEN_CURLY_OPEN;
|
|
|
|
|
|
+ return MiniJSON.TOKEN_CURLY_OPEN;
|
|
case '}':
|
|
case '}':
|
|
- return ShareMiniJSON.TOKEN_CURLY_CLOSE;
|
|
|
|
|
|
+ return MiniJSON.TOKEN_CURLY_CLOSE;
|
|
case '[':
|
|
case '[':
|
|
- return ShareMiniJSON.TOKEN_SQUARED_OPEN;
|
|
|
|
|
|
+ return MiniJSON.TOKEN_SQUARED_OPEN;
|
|
case ']':
|
|
case ']':
|
|
- return ShareMiniJSON.TOKEN_SQUARED_CLOSE;
|
|
|
|
|
|
+ return MiniJSON.TOKEN_SQUARED_CLOSE;
|
|
case ',':
|
|
case ',':
|
|
- return ShareMiniJSON.TOKEN_COMMA;
|
|
|
|
|
|
+ return MiniJSON.TOKEN_COMMA;
|
|
case '"':
|
|
case '"':
|
|
- return ShareMiniJSON.TOKEN_STRING;
|
|
|
|
|
|
+ return MiniJSON.TOKEN_STRING;
|
|
case '0':
|
|
case '0':
|
|
case '1':
|
|
case '1':
|
|
case '2':
|
|
case '2':
|
|
@@ -432,9 +432,9 @@ public class ShareMiniJSON
|
|
case '8':
|
|
case '8':
|
|
case '9':
|
|
case '9':
|
|
case '-':
|
|
case '-':
|
|
- return ShareMiniJSON.TOKEN_NUMBER;
|
|
|
|
|
|
+ return MiniJSON.TOKEN_NUMBER;
|
|
case ':':
|
|
case ':':
|
|
- return ShareMiniJSON.TOKEN_COLON;
|
|
|
|
|
|
+ return MiniJSON.TOKEN_COLON;
|
|
}
|
|
}
|
|
index--;
|
|
index--;
|
|
|
|
|
|
@@ -450,7 +450,7 @@ public class ShareMiniJSON
|
|
json[index + 4] == 'e' )
|
|
json[index + 4] == 'e' )
|
|
{
|
|
{
|
|
index += 5;
|
|
index += 5;
|
|
- return ShareMiniJSON.TOKEN_FALSE;
|
|
|
|
|
|
+ return MiniJSON.TOKEN_FALSE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -463,7 +463,7 @@ public class ShareMiniJSON
|
|
json[index + 3] == 'e' )
|
|
json[index + 3] == 'e' )
|
|
{
|
|
{
|
|
index += 4;
|
|
index += 4;
|
|
- return ShareMiniJSON.TOKEN_TRUE;
|
|
|
|
|
|
+ return MiniJSON.TOKEN_TRUE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -476,11 +476,11 @@ public class ShareMiniJSON
|
|
json[index + 3] == 'l' )
|
|
json[index + 3] == 'l' )
|
|
{
|
|
{
|
|
index += 4;
|
|
index += 4;
|
|
- return ShareMiniJSON.TOKEN_NULL;
|
|
|
|
|
|
+ return MiniJSON.TOKEN_NULL;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- return ShareMiniJSON.TOKEN_NONE;
|
|
|
|
|
|
+ return MiniJSON.TOKEN_NONE;
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
#endregion
|
|
@@ -714,25 +714,25 @@ public static class MiniJsonExtensions
|
|
{
|
|
{
|
|
public static string toJson( this Hashtable obj )
|
|
public static string toJson( this Hashtable obj )
|
|
{
|
|
{
|
|
- return ShareMiniJSON.jsonEncode( obj );
|
|
|
|
|
|
+ return MiniJSON.jsonEncode( obj );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string toJson( this Dictionary<string,string> obj )
|
|
public static string toJson( this Dictionary<string,string> obj )
|
|
{
|
|
{
|
|
- return ShareMiniJSON.jsonEncode( obj );
|
|
|
|
|
|
+ return MiniJSON.jsonEncode( obj );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ArrayList arrayListFromJson( this string json )
|
|
public static ArrayList arrayListFromJson( this string json )
|
|
{
|
|
{
|
|
- return ShareMiniJSON.jsonDecode( json ) as ArrayList;
|
|
|
|
|
|
+ return MiniJSON.jsonDecode( json ) as ArrayList;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Hashtable hashtableFromJson( this string json )
|
|
public static Hashtable hashtableFromJson( this string json )
|
|
{
|
|
{
|
|
- return ShareMiniJSON.jsonDecode( json ) as Hashtable;
|
|
|
|
|
|
+ return MiniJSON.jsonDecode( json ) as Hashtable;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|