.net中如何查询Json数据中的指定值
--------------------编程问答-------------------- 等这么久都每人回答啊,算了我已经知道了。结贴 --------------------编程问答--------------------json = json.Trim();--------------------编程问答-------------------- 只能将json数据转化成后台类对象,然后就可以类对象.date,类对象.pfprice这样点出来了,具体到网上搜很多这方面的例子。 --------------------编程问答-------------------- 行吧,给你贴点代码:
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]就是对应的属性值
}
}
}
[DataContract]
public class QQLogin
{
private string _ret;
private string _msg;
private string _nickname;
private string _figureurl;
private string _figureurl_1;
private string _figureurl_2;
private string _gender;
private string _vip;
private string _level;
private string _is_yellow_year_vip;
[DataMember(Name = "ret")]
public string Ret
{
get { return _ret; }
set { _ret = value; }
}
[DataMember(Name = "msg")]
public string Msg
{
get { return _msg; }
set { _msg = value; }
}
[DataMember(Name = "nickname")]
public string Nickname
{
get { return _nickname; }
set { _nickname = value; }
}
[DataMember(Name = "figureurl")]
public string Figureurl
{
get { return _figureurl; }
set { _figureurl = value; }
}
[DataMember(Name = "figureurl_1")]
public string Figureurl_1
{
get { return _figureurl_1; }
set { _figureurl_1 = value; }
}
[DataMember(Name = "figureurl_2")]
public string Figureurl_2
{
get { return _figureurl_2; }
set { _figureurl_2 = value; }
}
[DataMember(Name = "gender")]
public string Gender
{
get { return _gender; }
set { _gender = value; }
}
[DataMember(Name = "vip")]
public string Vip
{
get { return _vip; }
set { _vip = value; }
}
[DataMember(Name = "level")]
public string Level
{
get { return _level; }
set { _level = value; }
}
[DataMember(Name = "is_yellow_year_vip")]
public string Is_yellow_year_vip
{
get { return _is_yellow_year_vip; }
set { _is_yellow_year_vip = value; }
}
}
声明这样的实体对象。
然后这样调用就可以了:
JsonQueryStringConverter convert = new JsonQueryStringConverter();
QQLogin relations = new QQLogin();
relations = (QQLogin)convert.ConvertStringToValue(temp, relations.GetType());
声明:
temp就是你的json字符串。照着做,肯定没有问题。 --------------------编程问答--------------------
--------------------编程问答-------------------- json你可以把它当成xml的简化版. 就让它经过反序列化,变成.net真正的“对象”。这样不管你用linq还是循环都好查了。
AjaxSubmit("GET",_url,{"GameType":_this.GameType,"Vid":id,"TopNum":6},function(data){
var htmlvar;var html_body="";
var html_header = '<table class="bidHistoryList">'
+ '<tr class="no1"><td class="no1_1">会员</td><td class="no1_2">IP</td><td class="no1_3">地址</td><td class="no1_4">参于价</td></tr>';
var html_footer='</table>';//
data = eval("(" + data + ")");
if(data["all"]){
jQuery.each(data["all"], function(i,n){
var item = n;
html_body+='<tr class="no2"><td class="no2_1"><a style="margin-left:0px">'+ item.nickname +'</a></td>'
+ '<td class="no2_2"><a style="margin-left:0px">' + _this.FormatIp( item.ip ) + '</a></td>'
+ '<td class="no2_3"><a style="margin-left:0px">' + item.locate + '</a></td>'
+ '<td class="no2_4"><a style="margin-left:0px">¥'+ item.price +'</a></td>'
+ '</tr>';
});
}
补充:.NET技术 , ASP.NET