【问题标题】:Xamarin Forms - Output Observable Collection to JSONXamarin Forms - 将 Observable 集合输出到 JSON
【发布时间】:2020-08-11 00:59:34
【问题描述】:

我有一个绑定到 ListView 的 Observable 集合。

Observable Collection 中的内容包含产品名称、产品描述和产品价格,这些都显示在 ListView 中。

还有一些附加字段,例如产品 ID 等,从 ListView 中隐藏,但在 Observable 集合中。

这个 Observable 集合中会有多个项目。

我想将此 observable 集合输出为 JSON 包,以便通过 API 提交。

这是我的具有可观察集合的代码。

public static ObservableCollection<FBProduct> fbproducts = new ObservableCollection<FBProduct>();

下面是我如何简单地将项目添加到 Observable 集合中。

Payment.SelectedProductID = foo.id;
Payment.SelectedProductTitle = foo.title;
Payment.SelectedProductPrice = foo.price;
Payment.SelectedProductFeaturedImage = foo.featured_src;

如何将此 Observable 集合输出为 JSON 包,以便显示如下内容:

"line_items": [
   {
   "product_id": 1234,
   "product_name": apple,
   "product_price": 12,
   "product_description": green apple,
   "quantity": 1
   },
   {
   "product_id": 9876,
   "product_name": pear,
   "product_price": 10,
   "product_description": green pear,
   "quantity": 1
   },
],

【问题讨论】:

    标签: c# ios xamarin.forms xamarin.ios observablecollection


    【解决方案1】:

    使用Newtonsoft

    string json = JsonConvert.SerializeObject(fbproducts);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-25
      • 1970-01-01
      • 2021-09-11
      • 1970-01-01
      • 2012-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多