因为写JsonReader和JsonWriter的时候有依赖,为了便于说明问题。单独把JsonScope列出来,请大家理解哈。 从这些常量,我们可以简单的理解下Gson设计思想的一些方面,比如,逻辑层次、颗粒度等 随着大家编码经验越来越多,相信很多人已经认识到了颗粒度划分和层次划分的重要,这行能力对大家转型做设计(架构师)具有很大的意义。
EMPTY_DOCUMENT 和 NONEMPTY_DOCUMENT 文档 EMPTY_ARRAY 和 NONEMPTY_ARRAY 数珠 EMPTY_OBJECT 和 NONEMPTY_OBJECT。 对象(和map类似,所有的值都是key-value的形式),先输出key(name)然后才输出value,所以需要增加一个常量DANGLING_NAME CLOSED所有操作结束后变成close状态,不能够再做任何操作
/** * Lexical scoping elements within a JSON reader or writer. * * @author Jesse Wilson * @since 1.6 */ final class JsonScope { /** * An array with no elements requires no separators or newlines before * it is closed. */ static final int EMPTY_ARRAY = 1; /** * A array with at least one value requires a comma and newline before * the next element. */ static final int NONEMPTY_ARRAY = 2; /** * An object with no name/value pairs requires no separators or newlines * before it is closed. */ static final int EMPTY_OBJECT = 3; /** * An object whose most recent element is a key. The next element must * be a value. */ static final int DANGLING_NAME = 4; /** * An object with at least one name/value pair requires a comma and * newline before the next element. */ static final int NONEMPTY_OBJECT = 5; /** * No object or array has been started. */ static final int EMPTY_DOCUMENT = 6; /** * A document with at an array or object. */ static final int NONEMPTY_DOCUMENT = 7; /** * A document that's been closed and cannot be accessed. */ static final int CLOSED = 8; }
JsonScope
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.