C # in a format and generates City alphabetical method

                var dict=new Dictionary<string, object>();
                var pinYinLetter = new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
                foreach(var letter in pinYinLetter)
                {
                    var cityList = cacheList.Where(c => c.FirstPinYin == letter).Select(c => new CityList() { Name = c.Name, Short = c.SimplePinYin, Text = c.SimplePinYin + " " + c.Name, Value = c.CityId });
                    if (cityList != null && cityList.Count() > 0)
                        dict.Add(letter, cityList);
                }
                var cityData = new { status = "200", list = DataHelper.DicToDynamic(dict) };

It generates data in the following format:

{
    "status": "200",
    "list": {
        "a": [
            {
                "name": "安庆",
                "short": "aq",
                "value": "anqing",
                "text": "
            },"aq Anqing
                "
            {name": "安阳",
                "short": "ay",
                "value": "anyang",
                "text": "ay 安阳"
            }
        ],
        "b": [
            {
                "name": "北京",
                "short": "bj",
                "value": "beijing",
                "text": "bj 北京"
            }
        ],
        "c": [
            {
                "name": "长沙",
                "short": "cs",
                "value": "changsha",
                "text": "cs 长沙"
            }
        ],
        "d": [
            {
                "name": "大连",
                "short": "dl",
                "value": "dalian",
                "text": "dl 大连"
            },
            {
                "name": "大庆",
                "short": "dq",
                "value": "daqin",
                "text": "dq 大庆"
            }
        ],
        "h": [
            {
                "name": "合肥",
                "short": "hf",
                "value": "hefei",
                "text": "hf 合肥"
            }
        ],
        "w": [
            {
                "name": "武汉",
                "short": "wh",
                "value": "wuhan",
                "text": " WH Wuhan " 
            } 
        ] 
    } 
}

Guess you like

Origin www.cnblogs.com/firstcsharp/p/12173022.html