【问题标题】:Json Response get single fields (Appwrite)Json Response 获取单个字段(Appwrite)
【发布时间】:2021-06-14 12:40:02
【问题描述】:

目前我正在使用 Appwrite(自托管数据库)。 当我想用这段代码读取数据时:

Future result = database.listDocuments(collectionId: "60be22axxxxxx");

          result.then((response) {
            print(response);
          }).catchError((error) {});

...我得到以下 Json 响应:

{"sum":2,"documents":[{"$id":"60bf87c9a9726","$collection":"60be22a7c4a95","$permissions":{"read":["*"],"write":["*"]},"title":"test"},{"$id":"60bf95c0af7af","$collection":"60be22a7c4a95","$permissions":{"read":["*"],"write":["*"]},"title":"tes","desc":"des"}]}

如何从 db 文档中获取像 title 这样的单个字段并将其保存到字符串或更好的对象中?

【问题讨论】:

    标签: flutter dart appwrite


    【解决方案1】:

    试试这样,

    String data = jsonDecode(response);
    Print(["documents"][0]["title"]);
    

    [0] 是 2 的第一个,您可以使用 [1] 获得第二个,或者部署一个圆球。

    【讨论】:

    • 感谢您的回答,同时我得到了完全相同的解决方案。
    猜你喜欢
    • 2014-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-16
    • 1970-01-01
    • 1970-01-01
    • 2022-10-17
    • 2016-09-24
    相关资源
    最近更新 更多