@@ -348,7 +348,7 @@ protected Object parse(String name) {
348
348
// string
349
349
case '\'' :
350
350
case '\"' :
351
- value = parseString ();
351
+ value = parseString (true );
352
352
break ;
353
353
// number
354
354
case '0' : case '1' : case '2' : case '3' : case '4' : case '5' :
@@ -395,7 +395,7 @@ protected Object parseObject(String name){
395
395
read ('{' );
396
396
char current = get ();
397
397
while (get () != '}' ) {
398
- String key = parseString ();
398
+ String key = parseString (false );
399
399
read (':' );
400
400
Object value = parse (key );
401
401
doCallback (key , value );
@@ -505,22 +505,31 @@ public char get() {
505
505
* @return the next string.
506
506
* @throws JSONParseException if invalid JSON is found
507
507
*/
508
- public String parseString () {
509
- char quot ;
508
+ public String parseString (boolean needQuote ) {
509
+ char quot = 0 ;
510
510
if (check ('\'' ))
511
511
quot = '\'' ;
512
512
else if (check ('\"' ))
513
513
quot = '\"' ;
514
- else
514
+ else if ( needQuote )
515
515
throw new JSONParseException (s , pos );
516
516
517
517
char current ;
518
518
519
- read (quot );
519
+ if (quot > 0 )
520
+ read (quot );
520
521
StringBuilder buf = new StringBuilder ();
521
522
int start = pos ;
522
- while (pos < s .length () &&
523
- (current = s .charAt (pos )) != quot ) {
523
+ while (pos < s .length ()) {
524
+ current = s .charAt (pos );
525
+ if (quot > 0 ) {
526
+ if (current == quot )
527
+ break ;
528
+ } else {
529
+ if (current == ':' || current == ' ' )
530
+ break ;
531
+ }
532
+
524
533
if (current == '\\' ) {
525
534
pos ++;
526
535
@@ -565,9 +574,9 @@ else if(check('\"'))
565
574
}
566
575
pos ++;
567
576
}
568
- read ( quot );
569
-
570
- buf . append ( s . substring ( start , pos - 1 ));
577
+ buf . append ( s . substring ( start , pos ) );
578
+ if ( quot > 0 )
579
+ read ( quot );
571
580
return buf .toString ();
572
581
}
573
582
0 commit comments