【问题标题】:How to work with an JSON response which gives me an Array with Objects to setup my ListView如何使用 JSON 响应,它为我提供了一个带有对象的数组来设置我的 ListView
【发布时间】:2016-02-11 03:16:59
【问题描述】:

我有一个 View 组件,它有一个 ListView 填充 JSON 数据。我将 FLUX 模式用于我的数据流。 现在,当我收到一个 JSON 响应“_userNews”,它有多个数组,每个数组中有对象,打印出我的 ListView 项目的最佳方法是什么?对象包含一个数组和 4 个字符串。我需要对象中的数组项以及我想在我的 ListView 中打印出来的 2 个字符串。 我是编程的菜鸟,只是想在程序员的世界和学习中挣扎。也许有人对我如何使用数组/对象有提示。

【问题讨论】:

    标签: arrays object react-native flux


    【解决方案1】:

    一些提示:

    • 使用 GSON 将 JSON 映射到类模型。 例如:Json to Gson - Modeling

    • 使用模型的 toString 或新的 api toListItemString 与 ListView 一起使用。

      class Thing
      {
          String id;
          String name;
          String notRequired;
          List<String> object2;
      
          public String toListItemString(){
              return this.id + "\n" +  this.name + "\n" + Arrays.toString(object2);
          }
      }
      

    请分享示例 JSON 以获得更具体的响应。

    【讨论】:

    • 这对 React Native 也有效吗?我很久以前在我的 Android / Java 项目中使用过 GSON,但不知道这也适用于 JavaScript...
    • 不确定我是否理解正确。对于 GSON/JS,我找到了一个链接:stackoverflow.com/questions/22777930/…
    猜你喜欢
    • 1970-01-01
    • 2017-09-18
    • 2021-02-01
    • 1970-01-01
    • 2021-10-10
    • 2021-04-02
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多