来自 GetResponseStream 的数据



如何获取从 HttpWebRequest 收到的此数据的sub_category_en?我只想要收到的数据的两到三个字段。

02-14 16:33:56.793 I/mono-stdout( 8974): { 02-14 16:33:56.795 I/mono-stdout( 8974): "active": 1, 02-14 16:33:56.797 I/mono-stdout( 8974): "child_level": 1, 02-14 16:33:56.798 I/mono-stdout( 8974): "create_date": "2015-08-27T17:24:58.19+03:00", 02-14 16:33:56.798 I/mono-stdout( 8974): "description_ar": "", 02-14 16:33:56.800 I/mono-stdout( 8974): "description_en": "", 02-14 16:33:56.802 I/mono-stdout( 8974): "has_child": 1, 02-14 16:33:56.805 I/mono-stdout( 8974): "id": 1881, 02-14 16:33:56.805 I/mono-stdout( 8974): "id_category": 3, 02-14 16:33:56.808 I/mono-stdout( 8974): "id_parent": 0, 02-14 16:33:56.811 I/mono-stdout( 8974): "id_parents": "0", 02-14 16:33:56.811 I/mono-stdout( 8974): "id_user": 1, 02-14 16:33:56.811 I/mono-stdout( 8974): "last_update": "2015-08-27T17:24:58.19+03:00", 02-14 16:33:56.814 I/mono-stdout( 8974): "last_updated_by": 1, 02-14 16:33:56.815 I/mono-stdout( 8974): "meta_keyword_ar": "", 02-14 16:33:56.815 I/mono-stdout( 8974): "meta_keyword_en": "", 02-14 16:33:56.815 I/mono-stdout( 8974): "order_by": 94, 02-14 16:33:56.815 I/mono-stdout( 8974): "sub_category_ar": "Trailers", 02-14 16:33:56.815 I/mono-stdout( 8974): "sub_category_en": "Trailers", 02-14 16:33:56.816 I/mono-stdout( 8974): "sub_category_name_parents_ar": null, 02-14 16:33:56.816 I/mono-stdout( 8974): "sub_category_name_parents_en": null, 02-14 16:33:56.816 I/mono-stdout( 8974): "sub_category_url": "trailers", 02-14 16:33:56.816 I/mono-stdout( 8974): "sub_category_url_parents": null 02-14 16:33:56.816 I/mono-stdout( 8974): }, 02-14 16:33:56.817 I/mono-stdout( 8974): { 02-14 16:33:56.817 I/mono-stdout( 8974): "active": 1, 02-14 16:33:56.817 I/mono-stdout( 8974): "child_level": 1, 02-14 16:33:56.817 I/mono-stdout( 8974): "create_date": "2015-08-27T17:25:14.31+03:00", 02-14 16:33:56.817 I/mono-stdout( 8974): "description_ar": "", 02-14 16:33:56.818 I/mono-stdout( 8974): "description_en": "", 02-14 16:33:56.818 I/mono-stdout( 8974): "has_child": 1, 02-14 16:33:56.818 I/mono-stdout( 8974): "id": 1882, 02-14 16:33:56.818 I/mono-stdout( 8974): "id_category": 3, 02-14 16:33:56.818 I/mono-stdout( 8974): "id_parent": 0, 02-14 16:33:56.818 I/mono-stdout( 8974): "id_parents": "0", 02-14 16:33:56.819 I/mono-stdout( 8974): "id_user": 1, 02-14 16:33:56.819 I/mono-stdout( 8974): "last_update": "2015-08-27T17:25:14.31+03:00", 02-14 16:33:56.819 I/mono-stdout( 8974): "last_updated_by": 1, 02-14 16:33:56.819 I/mono-stdout( 8974): "meta_keyword_ar": "", 02-14 16:33:56.819 I/mono-stdout( 8974): "meta_keyword_en": "", 02-14 16:33:56.820 I/mono-stdout( 8974): "order_by": 95, 02-14 16:33:56.820 I/mono-stdout( 8974): "sub_category_ar": "Aeroplanes", 02-14 16:33:56.820 I/mono-stdout( 8974): "sub_category_en": "Aeroplanes", 02-14 16:33:56.820 I/mono-stdout( 8974): "sub_category_name_parents_ar": null, 02-14 16:33:56.820 I/mono-stdout( 8974): "sub_category_name_parents_en": null, 02-14 16:33:56.821 I/mono-stdout( 8974): "sub_category_url": "aeroplanes", 02-14 16:33:56.821 I/mono-stdout( 8974): "sub_category_url_parents": null 02-14 16:33:56.821 I/mono-stdout( 8974): } 02-14 16:33:56.821 I/mono-stdout( 8974): ]

我在Visual Studio 2013中使用了xamarin。感谢您的帮助。如果使用这个Newtonsoft.Json.JsonSerializer是我的问题。我可以有一个小的示例代码吗?谢谢

您可以使用

JsonConvert.Deserialize 将 json 转换为自定义对象。

public class RootObject
{
    public int id { get; set; }
    public string sub_category_name { get; set; }
    public int child_level { get; set; }
    public int has_child { get; set; }
    public string sub_parent_url { get; set; }
}
class Program
{
    static void Main(string[] args)
    {
      WebRequest objRequest = HttpWebRequest.Create(dest);
      WebResponse objResponse = objRequest.GetResponse();
      using (StreamReader reader = new StreamReader(objResponse.GetResponseStream()))
      {
        string jsonString = reader.ReadToEnd();
        var data = JsonConvert.DeserializeObject<List<RootObject>>(jsonString);
      }
    }
}

相关内容

  • 没有找到相关文章

最新更新