This commit is contained in:
Ziver Koc 2015-03-23 21:05:51 +00:00
parent e822a4b35c
commit 91cadbb301
20 changed files with 342 additions and 130 deletions

View file

@ -99,11 +99,11 @@ public class DataNode implements Iterable<DataNode>{
* @return an JSONNode that contains the next level of the List or Map
*/
public DataNode get(int index){
if(map != null)
return map.get(""+index);
else if(list != null)
return list.get(index);
return null;
if(map != null)
return map.get(""+index);
else if(list != null)
return list.get(index);
return null;
}
/**
* @param index is the key in the Map

View file

@ -111,15 +111,14 @@ public class JSONParser{
case '\"':
root = new DataNode(DataType.String);
StringBuilder str = new StringBuilder();
while((c=(char)in.read()) != (char)-1 && c != '\"')
while((c=(char)in.read()) >= 0 && c != '\"')
str.append(c);
root.set(str.toString());
break;
// Parse unknown type
default:
StringBuilder tmp = new StringBuilder().append(c);
while((c=(char)in.read()) != (char)-1 && !Character.isWhitespace(c) &&
c != ',' && c != '='){
while((c=(char)in.read()) >= 0 && c != ',' && c != '='){
if(c == ']' || c == '}'){
end.i = 1;
break;
@ -127,7 +126,7 @@ public class JSONParser{
tmp.append(c);
}
// Check what type of type the data is
String data = tmp.toString();
String data = tmp.toString().trim();
if( BOOLEAN_PATTERN.matcher(data).matches() )
root = new DataNode(DataType.Boolean);
else if( NUMBER_PATTERN.matcher(data).matches() )
@ -140,4 +139,6 @@ public class JSONParser{
return root;
}
}