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

在于json。超级郁闷。上载了Newtonsoft.Json,可是没有JavaScriptArray属性,这是为什么呀

2012-09-08 
在于json。超级郁闷。下载了Newtonsoft.Json,可是没有JavaScriptArray属性,这是为什么呀我想要取新浪微博API

在于json。超级郁闷。下载了Newtonsoft.Json,可是没有JavaScriptArray属性,这是为什么呀
我想要取新浪微博API返回的JSON格式的值,因为本人没接触过这个,所以返回的json格式值解析不了,在网上找了一天了,终于看到有一个Newtonsoft.Json.dll,可以很简单的取到json的值。。。
可现在郁闷的是,我下载了Newtonsoft.Json.dll (我是vs2008 用NET3.5),引用上去后,命名空间也写了,可是就是找不到JavaScriptArray,

C# code
using System.Json;using Newtonsoft.Json;


Newtonsoft.Json 里面很多属性方法都有。可这是没JavaScript打头的方法。不知道是何原因。为此我也下了好几次dll

参照网上的方法是(来自http://topic.csdn.net/u/20120706/17/56e56164-6ac9-4ea4-88d3-ee9b9353a044.html 的huangwenquan123,感谢)


C# code
           string jsonStr = "{'order_no':'1205281338370004556','access_item':[{'commodity_id':'EZG20111130112304161','color':'red','size':'24','complex_access':'','access_content':''},{'commodity_id':'EZG20111130112304161','color':'','size':'','complex_access':'','access_content':''}]}";            JavaScriptObject jObject = JavaScriptConvert.DeserializeObject(jsonStr) as JavaScriptObject;            Console.WriteLine(jObject["order_no"]);            JavaScriptArray array = jObject["access_item"] as JavaScriptArray;            foreach (JavaScriptObject o in array)            {                Console.WriteLine("commodity_id:{0} color:{1} size:{2} complex_access:{3}", o["commodity_id"], o["color"], o["size"], o["complex_access"]);            }



新浪返回的值是这样的。不知道能否用这种方法取得。。。。。因为找不到方法,我现在还取不到值。急死我了。希望各位大哥帮助下。。



下面是新浪API 返回的值,大家帮忙参考下,如何取得值?
{"users":[{"id":1664714771,"idstr":"1664714771","screen_name":"潇洒小姐_Anna","name":"潇洒小姐_Anna","province":"34","city":"1","location":"安徽 合肥","description":"有梦想,爱生活,有些男孩子气的,小太阳。","url":"","profile_image_url":"http://tp4.sinaimg.cn/1664714771/50/5639554212/0","profile_url":"u/1664714771","domain":"","weihao":"","gender":"f","followers_count":4,"friends_count":21,"statuses_count":25,"favourites_count":1,"created_at":"Sun Nov 29 01:01:02 +0800 2009","following":false,"allow_all_act_msg":false,"geo_enabled":true,"verified":false,"verified_type":-1,"status_id":3478613078740177,"allow_all_comment":true,"avatar_large":"http://tp4.sinaimg.cn/1664714771/180/5639554212/0","verified_reason":"","follow_me":false,"online_status":0,"bi_followers_count":0,"lang":"zh-cn"},{"id":2881906024,"idstr":"2881906024","screen_name":"碧古轩","name":"碧古轩","province":"31","city":"1000","location":"上海","description":"","url":"","profile_image_url":"http://tp1.sinaimg.cn/2881906024/50/39998088511/0","profile_url":"u/2881906024","domain":"","weihao":"","gender":"f","followers_count":0,"friends_count":30,"statuses_count":24,"favourites_count":0,"created_at":"Fri Jul 27 17:51:39 +0800 2012","following":false,"allow_all_act_msg":false,"geo_enabled":true,"verified":false,"verified_type":-1,"status_id":3478607060227660,"allow_all_comment":true,"avatar_large":"http://tp1.sinaimg.cn/2881906024/180/39998088511/0","verified_reason":"","follow_me":false,"online_status":0,"bi_followers_count":0,"lang":"zh-cn"},{"id":2452112782,"idstr":"2452112782","screen_name":"紫伊藍1","name":"紫伊藍1","province":"44","city":"1","location":"广东 广州","description":"","url":"","profile_image_url":"http://tp3.sinaimg.cn/2452112782/50/5612951752/0","profile_url":"u/2452112782","domain":"","weihao":"","gender":"f","followers_count":37,"friends_count":362,"statuses_count":351,"favourites_count":1,"created_at":"Fri Oct 07 18:46:33 +0800 2011","following":false,"allow_all_act_msg":false,"geo_enabled":true,"verified":false,"verified_type":-1,"status_id":3478614471392060,"allow_all_comment":false,"avatar_large":"http://tp3.sinaimg.cn/2452112782/180/5612951752/0","verified_reason":"","follow_me":false,"online_status":0,"bi_followers_count":36,"lang":"zh-cn"}],"next_cursor":4,"previous_cursor":1,"total_number":181144}



[解决办法]
应该是dll的版本问题,你的应该较新

修改如下

C# code
string jsonStr = "{'order_no':'1205281338370004556','access_item':[{'commodity_id':'EZG20111130112304161','color':'red','size':'24','complex_access':'','access_content':''},{'commodity_id':'EZG20111130112304161','color':'','size':'','complex_access':'','access_content':''}]}";            JObject jObject = JsonConvert.DeserializeObject(jsonStr) as JObject;            JArray array = jObject["access_item"] as JArray;            foreach (JObject  o in array)            {                Console.WriteLine("commodity_id:{0} color:{1} size:{2} complex_access:{3}", o["commodity_id"], o["color"], o["size"], o["complex_access"]);            }
[解决办法]
教楼主个好办法无需第三方控件。

public class XLJson
{
public List<UserInfo> users { get; set; }
public string next_cursor { get; set; }
public string ious_cursor { get; set; }
public string total_number { get; set; }
}
public class UserInfo
{
public string id { get; set; }
public string city { get; set; }

}
新建个类如上
string jsonstr = @"
{""users"":[{""id"":1664714771,""idstr"":""1664714771"",""screen_name"":""潇洒小姐_Anna"",""name"":""潇洒小姐_Anna"",""province"":""34"",""city"":""1"",""location"":""安徽 合肥"",""description"":""有梦想,爱生活,有些男孩子气的,小太阳。"",""url"":"""",""profile_image_url"":""http://tp4.sinaimg.cn/1664714771/50/5639554212/0"",""profile_url"":""u/1664714771"",""domain"":"""",""weihao"":"""",""gender"":""f"",""followers_count"":4,""friends_count"":21,""statuses_count"":25,""favourites_count"":1,""created_at"":""Sun Nov 29 01:01:02 +0800 2009"",""following"":false,""allow_all_act_msg"":false,""geo_enabled"":true,""verified"":false,""verified_type"":-1,""status_id"":3478613078740177,""allow_all_comment"":true,""avatar_large"":""http://tp4.sinaimg.cn/1664714771/180/5639554212/0"",""verified_reason"":"""",""follow_me"":false,""online_status"":0,""bi_followers_count"":0,""lang"":""zh-cn""},{""id"":2881906024,""idstr"":""2881906024"",""screen_name"":""碧古轩"",""name"":""碧古轩"",""province"":""31"",""city"":""1000"",""location"":""上海"",""description"":"""",""url"":"""",""profile_image_url"":""http://tp1.sinaimg.cn/2881906024/50/39998088511/0"",""profile_url"":""u/2881906024"",""domain"":"""",""weihao"":"""",""gender"":""f"",""followers_count"":0,""friends_count"":30,""statuses_count"":24,""favourites_count"":0,""created_at"":""Fri Jul 27 17:51:39 +0800 2012"",""following"":false,""allow_all_act_msg"":false,""geo_enabled"":true,""verified"":false,""verified_type"":-1,""status_id"":3478607060227660,""allow_all_comment"":true,""avatar_large"":""http://tp1.sinaimg.cn/2881906024/180/39998088511/0"",""verified_reason"":"""",""follow_me"":false,""online_status"":0,""bi_followers_count"":0,""lang"":""zh-cn""},{""id"":2452112782,""idstr"":""2452112782"",""screen_name"":""紫伊藍1"",""name"":""紫伊藍1"",""province"":""44"",""city"":""1"",""location"":""广东 广州"",""description"":"""",""url"":"""",""profile_image_url"":""http://tp3.sinaimg.cn/2452112782/50/5612951752/0"",""profile_url"":""u/2452112782"",""domain"":"""",""weihao"":"""",""gender"":""f"",""followers_count"":37,""friends_count"":362,""statuses_count"":351,""favourites_count"":1,""created_at"":""Fri Oct 07 18:46:33 +0800 2011"",""following"":false,""allow_all_act_msg"":false,""geo_enabled"":true,""verified"":false,""verified_type"":-1,""status_id"":3478614471392060,""allow_all_comment"":false,""avatar_large"":""http://tp3.sinaimg.cn/2452112782/180/5612951752/0"",""verified_reason"":"""",""follow_me"":false,""online_status"":0,""bi_followers_count"":36,""lang"":""zh-cn""}],""next_cursor"":4,""previous_cursor"":1,""total_number"":181144}


";

JavaScriptSerializer js = new JavaScriptSerializer();
XLJson xljson = js.Deserialize<XLJson>(jsonstr);
下面是调用法

热点排行