google closure compiler and json

后端 未结 3 1324
礼貌的吻别
礼貌的吻别 2021-02-08 04:30

I have a json string that I parse and then access the properties of the object with the dot notation. However, in the google closure compiler, the dot notation (MyObject.P

3条回答
  •  别那么骄傲
    2021-02-08 04:57

    You basically have two choices:

    1. use object array access using the string literal (aka MyJsonObject['PropertyName']) this is the simple solution.
    2. create a extern file describing the properties in your JSON object and then use dot notation (aka MyJsonObject.PropertyName). This requires more maintenance but allows the compiler to type check the properties if you provide type annotations in your extern description.

提交回复
热议问题