var list = ArrayList<JsonValue>(); list.append(JsonBool(true)) list.append(JsonInt(7363)) list.append(JsonString("abc")) var jsa= JsonArray(list); Hilog.printInfo("printInfo", jsa.toString())
}
2-打印消息
1
[true,7363,"abc"]
三 JsonValue和String相互转换
1-示例代码
1 2 3 4 5 6 7 8 9 10 11 12
protected override func onPageShow() {
//1-string->JsonValue var str:String = ##"{"name": "zs","age": 30}"##; var jv: JsonValue = JsonValue.fromStr(str) //2-JsonValue->String var res = jv.toString() var prettyres = jv.toJsonString() Hilog.printInfo("printInfo",res) Hilog.printInfo("printInfo",prettyres)
//1-string->JsonValue->DataModel->Bean var js = ##"{"name": "A","age": 30}"## var jv = JsonValue.fromStr(js) var dm = DataModel.fromJson(jv) var A = Person.deserialize(dm) Hilog.printInfo("printInfo","name == ${A.name}") Hilog.printInfo("printInfo","age == ${A.age}") //2-Bean->DataModel->JsonValue->JsonObject dm = A.serialize() var jo = dm.toJson().asObject() Hilog.printInfo("printInfo",jo.toJsonString())