0

HttpWebRequest から受け取ったこのデータで sub_category_en を取得するにはどうすればよいですか? 受信したデータの 2 ~ 3 つのフィールドが必要です。

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 を使用することが私の問題です。小さなサンプルコードをいただけますか? ありがとう

4

1 に答える 1

0

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);

      }
    }
}
于 2016-02-17T07:58:46.183 に答える