31059


DynamicJsonを導入しjsonファイルのパースを行っていますが

[code]

            dynamic obj = DynamicJson.Parse(json);
            string movie_width= obj.streams.width;
    
[/code]

文字入力が違うとエラーが出ます。  
どう記述するのが正解なのでしょうか？

### json内容

[code]

    {
        "streams": [
            {
                "index": 0,
                "codec_name": "h264",
                "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
                "profile": "Constrained Baseline",
                "codec_type": "video",
                "codec_time_base": "1/48",
                "codec_tag_string": "avc1",
                "codec_tag": "0x31637661",
                "width": 640,
                "height": 360,
                "coded_width": 640,
                "coded_height": 360,
                "has_b_frames": 0,
                "sample_aspect_ratio": "1:1",
                "display_aspect_ratio": "16:9",
                "pix_fmt": "yuv420p",
                "level": 30,
                "chroma_location": "left",
                "refs": 1,
                "is_avc": "true",
                "nal_length_size": "4",
                "r_frame_rate": "24/1",
                "avg_frame_rate": "24/1",
                "time_base": "1/12288",
                "start_pts": 0,
                "start_time": "0.000000",
                "duration_ts": 36864,
                "duration": "3.000000",
                "bit_rate": "351098",
                "bits_per_raw_sample": "8",
                "nb_frames": "72",
                "disposition": {
                    "default": 1,
                    "dub": 0,
                    "original": 0,
                    "comment": 0,
                    "lyrics": 0,
                    "karaoke": 0,
                    "forced": 0,
                    "hearing_impaired": 0,
                    "visual_impaired": 0,
                    "clean_effects": 0,
                    "attached_pic": 0,
                    "timed_thumbnails": 0
                },
                "tags": {
                    "language": "und",
                    "handler_name": "VideoHandler"
                }
            }
        ]
    }
    
[/code]


CC BY-SA 3.0
2016-12-09T12:13:17.307
31053
2016-12-09T14:38:37.507
2020-06-17T08:14:45.997
-1
12778
question
c# json
C#でjsonファイルのパースが失敗します。


> string movie_width= obj.streams.width;

これは以下の二点が記載のJSONとは異なります。

  * `streams`は配列なので`[0]`が必要
  * `width`の型は`number`

よって正しくは以下のようになります。

[code]

    double movie_width = obj.streams[0].width;
    
[/code]


CC BY-SA 3.0
2016-12-09T14:38:37.507
31059
2016-12-09T14:38:37.507
5750
31053
answer