我有一个字符串,它是一个字典数组的字符串。
格式示例如下:
[{"id":1,"items":[5,8]},{"id":2,"items":[6]},{"id":3,"items":[7]}]
(注:以上代码均为字符串)
所以这里是一个字典数组的字符串,有两个键,第一个键的值是一个数字,第二个键的值是一个数字数组。
使用 c#(开箱即用程序集),我如何遍历所有 id 值,然后遍历所有项数组值。
所以我希望有一个双 for 循环。一个遍历 id 并提取数字,然后对于每次迭代,它需要遍历 items 数组的所有值。
有谁知道如何解析和提取数字?
谢谢。
输出就像(例如)
1
 5  8
2
 6
3
 7
编辑:
我试过这个:
            string dataString = JSONValue.Text;
            JavaScriptSerializer jss = new JavaScriptSerializer();
            var json = new JavaScriptSerializer();
            var data = json.Deserialize<List<Dictionary<string, Object>>>(dataString);
            int sectionID;
            List<int> itemIDS;
            foreach (Dictionary<string, Object> dict in data)
            {
                sectionID = (int)dict["id"];
                itemIDS = (List<int>)dict["items"];
                ReportObject.log(sectionID.ToString());
                foreach (int itemID in itemIDS)
                {
                    ReportObject.log(itemID.ToString());
                }
            }
但我越来越
(6/27/2013 12:02:04 AM) - Error Message: Unable to cast object of type 'System.Collections.ArrayList' to type 'System.Collections.Generic.List`1[System.Int32]'.