Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

json bugfix

commit 2b1678ba88d3825dd4f2df96146c28faa40099aa 1 parent 978672c
azrael authored

Showing 1 changed file with 18 additions and 9 deletions. Show diff stats Hide diff stats

  1. +18 9 jsonparser.js
27 jsonparser.js
@@ -17,19 +17,31 @@
17 17 if(token === null){
18 18 throw new Error('not json');
19 19 }
20   - preter.eat();
  20 + preter.eat();//吞掉{
21 21 handleProperties(result, preter);
22 22 return result;
23 23 };
24 24
25 25 function handleProperties(obj, preter){
26   - var token, str, prop, value, tmpObj;
27   - while((token = preter.eatUntil(['}', '"'])) !== null){
  26 + var token, str, prop, value, tmpObj, propState;
  27 + while((token = preter.eatUntil(['}', '"', ':'])) !== null){
  28 + propState = false;
28 29 str = preter.eat();
29   - if(str === '"'){//property start
  30 + if(str === '}'){//obj结束了
  31 + return;
  32 + }
  33 + if(str === '"'){
  34 + //property start
30 35 prop = preter.eatUntil(str);
31   - preter.eatUntil(':');
  36 + preter.eatUntil(':');//吞掉属性后面的引号和空白
32 37 preter.eat();//吞掉:
  38 + propState = true;
  39 + }
  40 + if(str === ':'){
  41 + prop = token.trim();
  42 + propState = true;
  43 + }
  44 + if(propState){
33 45 token = preter.eatUntil([',', '{', '}', '[']);
34 46 str = preter.eat();//吞掉,或}{
35 47 if(str === ','){
@@ -58,10 +70,7 @@
58 70 }
59 71 }
60 72 }
61   - }else if(str === '}'){
62   - //obj结束了
63   - return;
64   - }
  73 + }//end propState
65 74 }
66 75 }
67 76

0 comments on commit 2b1678b

Please sign in to comment.
Something went wrong with that request. Please try again.