首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#上怎样取到JSon文件里面的部分属性

2013-03-13 
C#下怎样取到JSon文件里面的部分属性 //配置服务器CouchbaseClientConfiguration mbcc new CouchbaseCli

C#下怎样取到JSon文件里面的部分属性
 //配置服务器                                
                                CouchbaseClientConfiguration mbcc = new CouchbaseClientConfiguration();
                                //使用默认的数据库  
                                mbcc.Urls.Add(new Uri("http://10.10.10.37:8091/pools/default"));

                                //建立一个Client,装入Client的配置                              
                                
                                CouchbaseClient client = new CouchbaseClient(mbcc);
                                string str = "{"POIInfo":"" + pair.Value.Pguid.ToString() + "_" + (m++).ToString() + "_" + (n++).ToString() + "_" + ixx.ToString() + "","original":"" + poi.OriginalWord + "","
                                                + ""pguid":"" + poi.Pguid + "","originalpinyin":"" + poi.OriginalPinyin + "","originalfirstchar":"" + poi.OriginalFirstChar + "","type":"" + poi.Type + "","
                                                + ""longitude":"" + poi.Longitude + "","latitude":"" + poi.Latitude + "","areacode":"" + poi.AreaCode + "","poitype":"" + poi.POIType + "","typeboost":""
                                                + "" + poi.TypeBoost.ToString() + "","frequencyboost":"" + poi.FrequencyBoost.ToString() + "","name":"" + derive.DeriveName + "","derive":"" + entry.Replace(" ", "").Replace("|", " ").ToLower() + "","


                                                + ""pinyinderive":"" + entry.ToLower() + "","firstchar":"" + GetFirstChar(entry) + ""}";

                                var json =JsonConvert.DeserializeObject(str);

                                string output = JsonConvert.SerializeObject(json); 
                                //添加一条数据                                                                                         
                                bool b = client.Store(StoreMode.Add, "" + pair.Value.Pguid.ToString() + "_" + (suffix++).ToString() + "", output);

想查出部分属性,并显示。
[解决办法]

 json = json.Trim();
        if (json[0] != '[')
            json = "[" + json;
        if (json[json.Length - 1] != ']')
            json = json + "]";

        JavaScriptSerializer jss = new JavaScriptSerializer();
        ArrayList arrList = jss.Deserialize<ArrayList>(json);
        if (arrList.Count > 0)
        {
            foreach (Dictionary<string, object> arr in arrList)
            {
                  foreach (string key in arr.Keys)
                  {
                            //key就是属性
                                 //arr[key]就是对应的属性值


                  }
            }
        }

热点排行