【问题标题】:How to read a json file and transcribe it如何读取 json 文件并将其转录
【发布时间】:2021-12-28 14:24:35
【问题描述】:

我将这个json文件导入到项目中,你可以看到它是一个向量

    {
   "objArray": [
      {
         "min_position": 4,
         "has_more_items": false,
         "items_html": "Bike",
         "new_latent_count": 7
      },
      {
         "min_position": 9,
         "has_more_items": false,
         "items_html": "Car",
         "new_latent_count": 8
      },
      {
         "min_position": 9,
         "has_more_items": false,
         "items_html": "Bus",
         "new_latent_count": 8
      },
      {
         "min_position": 3,
         "has_more_items": true,
         "items_html": "Car",
         "new_latent_count": 1
      },
      {
         "min_position": 3,
         "has_more_items": false,
         "items_html": "Bus",
         "new_latent_count": 9
      }
   ]
}

我想问有没有办法把它全部阅读并转录成xamarin

【问题讨论】:

    标签: arrays json xamarin.forms


    【解决方案1】:

    使用Newtonsoft

    Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse); 
    

    来自json2csharp.com

    public class ObjArray
    {
        public int min_position { get; set; }
        public bool has_more_items { get; set; }
        public string items_html { get; set; }
        public int new_latent_count { get; set; }
    }
    
    public class Root
    {
        public List<ObjArray> objArray { get; set; }
    }
    

    【讨论】:

    • 非常感谢,如果我想在标签里面写内容怎么办?
    • 分配标签的Text 属性。或者使用数据绑定。有很多方法可以做到这一点
    • 我不明白它从哪里得到“myJsonResponse”,我创建了一个字符串变量并将其分配为我给项目中的 json 文件命名的值,但它给了我一个错误
    • 这是一个包含 json 数据的字符串。如果您将其作为文件保存在项目中,则需要先将其读入字符串变量
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-08
    • 1970-01-01
    • 2014-09-16
    • 2016-09-10
    • 1970-01-01
    • 2017-06-10
    相关资源
    最近更新 更多