【问题标题】:Get array out of json从json中获取数组
【发布时间】:2012-01-23 12:52:21
【问题描述】:

我想从 json 响应中的数组中获取数据。 这是json:

{
    "program":{
        "title":"show",
        "image_url":"NOA_17.jpg"
    },
    "noa":[
        {
            "title":"Title1",
            "artist":"Artist1",
        },
        {
            "title":"Title2",
            "artist":"Artist2",
        }
    ]
}

我想让 Title1 和 Artist1 离开那里。

我希望有人可以帮助我。

提前谢谢你。

【问题讨论】:

标签: c# arrays json serialization


【解决方案1】:

修复

        "artist":"Artist1",
        "artist":"Artist2",

        "artist":"Artist1"
        "artist":"Artist2"

例如

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Web.Script.Serialization;

class Sample {
    static void Main(){
        string json = File.ReadAllText("json.txt");
        var jss = new JavaScriptSerializer();
        var dic = jss.Deserialize<Dictionary<string, object>>(json);
        var noa = (ArrayList)dic["noa"];
        var noa_1 = (Dictionary<string, object>)noa[0];
        Console.WriteLine("title is {0}",noa_1["title"]);
        Console.WriteLine("artist is {0}",noa_1["artist"]);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多