From c3aeb89bbda9648632237d5e94d8828e630c7cf5 Mon Sep 17 00:00:00 2001 From: Stone Date: Fri, 16 Sep 2016 14:36:14 +0000 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=95=B0=E7=BB=84=E7=9A=84?= =?UTF-8?q?=E5=85=83=E7=B4=A0=E8=AE=A1=E6=95=B0=E5=92=8C=E5=8F=96=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Message/Json.cpp | 200 ++++++++++++++++++++++------------------------ Test/JsonTest.cpp | 6 +- 2 files changed, 102 insertions(+), 104 deletions(-) diff --git a/Message/Json.cpp b/Message/Json.cpp index 9a933a6e..34554dd8 100644 --- a/Message/Json.cpp +++ b/Message/Json.cpp @@ -1,5 +1,9 @@ #include "Json.h" +static bool isSpace(char ch); +static cstring SkipSpace(cstring str, int& len); +static int find(cstring str, int len, char ch); + static const Json Null; Json::Json() { Init(nullptr, 0); } @@ -11,8 +15,10 @@ Json::Json(cstring str) void Json::Init(cstring str, int len) { - _str = str; + //_str = str; _len = len; + + _str = SkipSpace(str, _len); } // 值类型 @@ -116,100 +122,6 @@ double Json::AsDouble() const return s.ToDouble(); } -bool isSpace(char ch) -{ - return ch == ' ' || - ch == '\t' || - ch == '\r' || - ch == '\n'; - -} - -// 跳过空格 -cstring SkipSpace(cstring str) -{ - while(isSpace(str[0])) str++; - - return str; -} - -// 读取对象结尾 -int readObject(cstring str, int len) -{ - // { ... } - if(str[0] != '{') return 0; - - // 记录括号配对 - int m = 0; - // 是否在字符串中,此时不算括号 - bool s = false; - for(int i=0; i