C# 如何提取json数据
我想从中检索一些流数据C# 如何提取json数据,c#,asp.net,json,C#,Asp.net,Json,我想从中检索一些流数据 “estimatedResultCount”:“399”来自以下数据 如何从这种方法中获得399值 解析JSON->responseData->cursor->estimatedResultCount将获得支持计数 { "responseData": { "results": [ { "GsearchResultClass": "GwebSearch",
“estimatedResultCount”:“399”
来自以下数据
如何从这种方法中获得399值
解析JSON->responseData->cursor->estimatedResultCount将获得支持计数
{
"responseData": {
"results": [
{
"GsearchResultClass": "GwebSearch",
"unescapedUrl": "http://www.homeocare.in/",
"url": "http://www.homeocare.in/",
"visibleUrl": "www.homeocare.in",
"cacheUrl": "http://www.google.com/search?q=cache:E7xF9dtFWgIJ:www.homeocare.in",
"title": "Homeopathy Clinics in Hyderabad - Homeopathy Treatment",
"titleNoFormatting": "Homeopathy Clinics in Hyderabad - Homeopathy Treatment",
"content": "Homeocare International - World Class Homeopathy Clinic in India provides \ninformation on causes, symptoms, and Homeopathy treatment of various \ndiseases."
},
{
"GsearchResultClass": "GwebSearch",
"unescapedUrl": "http://www.homeocare.in/contactus.html",
"url": "http://www.homeocare.in/contactus.html",
"visibleUrl": "www.homeocare.in",
"cacheUrl": "http://www.google.com/search?q=cache:zrjNDKonZY0J:www.homeocare.in",
"title": "Homeocare International | Contact Us",
"titleNoFormatting": "Homeocare International | Contact Us",
"content": "To get best Homeopathy treatment Contact Homeocare International through \nphone or fill contact form. We have branches all over South India."
},
{
"GsearchResultClass": "GwebSearch",
"unescapedUrl": "http://www.homeocare.in/testimonials.html",
"url": "http://www.homeocare.in/testimonials.html",
"visibleUrl": "www.homeocare.in",
"cacheUrl": "http://www.google.com/search?q=cache:oPJKzW6sHOkJ:www.homeocare.in",
"title": "Homeocare International Reviews / Testimonials",
"titleNoFormatting": "Homeocare International Reviews / Testimonials",
"content": "Homeocare International Reviews / Testimonials for Happy Patient. We pride \nourselves on excellent service, and our reviews show it!"
},
{
"GsearchResultClass": "GwebSearch",
"unescapedUrl": "http://www.homeocare.in/arthritis.html",
"url": "http://www.homeocare.in/arthritis.html",
"visibleUrl": "www.homeocare.in",
"cacheUrl": "http://www.google.com/search?q=cache:gqHnM_Tg0hcJ:www.homeocare.in",
"title": "Homeopathy Treatment for Arthritis | Arthritis Treatment",
"titleNoFormatting": "Homeopathy Treatment for Arthritis | Arthritis Treatment",
"content": "Get Homeopathy Treatment for arthritis and rheumatoid arthritis at Homeocare \nInternational provides safe and effective remedies with no side effects."
}
],
"cursor": {
"resultCount": "399",
"pages": [
{
"start": "0",
"label": 1
},
{
"start": "4",
"label": 2
},
{
"start": "8",
"label": 3
},
{
"start": "12",
"label": 4
},
{
"start": "16",
"label": 5
},
{
"start": "20",
"label": 6
},
{
"start": "24",
"label": 7
},
{
"start": "28",
"label": 8
}
],
"estimatedResultCount": "399",
"currentPageIndex": 0,
"moreResultsUrl": "http://www.google.com/search?oe=utf8&ie=utf8&source=uds&start=0&hl=en&q=site:homeocare.in",
"searchResultTime": "0.09"
}
},
"responseDetails": null,
"responseStatus": 200
}
代码
string strurl = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=site:homeocare.in";
StreamReader stream = objm.URLServerRequest(strurl);
string myResponse = stream.ReadToEnd();
public StreamReader URLServerRequest(string url)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
StreamReader stream = new StreamReader(request.GetResponse().GetResponseStream());
return stream;
}
您可以在这里生成类,这非常简单 假设您成功下载了json字符串,下面是作为控制台应用程序的代码。它使用json.net()
类程序
{
静态void Main(字符串[]参数)
{
var json=@“…json字符串…”;
var obj=JsonConvert.DeserializeObject(json);
Console.WriteLine(对象responseData.cursor.estimatedResultCount)
;
Console.ReadLine();
}
}
公开课成绩
{
公共字符串GsearchResultClass{get;set;}
公共字符串unescapedUrl{get;set;}
公共字符串url{get;set;}
公共字符串visibleUrl{get;set;}
公共字符串缓存URL{get;set;}
公共字符串标题{get;set;}
公共字符串标题格式{get;set;}
公共字符串内容{get;set;}
}
公共类页面
{
公共字符串开始{get;set;}
公共int标签{get;set;}
}
公共类游标
{
公共字符串resultCount{get;set;}
公共列表页{get;set;}
公共字符串estimatedResultCount{get;set;}
public int currentPageIndex{get;set;}
公共字符串moresultsurl{get;set;}
公共字符串searchResultTime{get;set;}
}
公共类响应数据
{
公共列表结果{get;set;}
公共游标{get;set;}
}
公共类根对象
{
公共响应数据响应数据{get;set;}
公共对象响应详细信息{get;set;}
公共int responseStatus{get;set;}
}
您可以在这里生成类,这非常简单
假设您成功下载了json字符串,下面是作为控制台应用程序的代码。它使用json.net()
类程序
{
静态void Main(字符串[]参数)
{
var json=@“…json字符串…”;
var obj=JsonConvert.DeserializeObject(json);
Console.WriteLine(对象responseData.cursor.estimatedResultCount)
;
Console.ReadLine();
}
}
公开课成绩
{
公共字符串GsearchResultClass{get;set;}
公共字符串unescapedUrl{get;set;}
公共字符串url{get;set;}
公共字符串visibleUrl{get;set;}
公共字符串缓存URL{get;set;}
公共字符串标题{get;set;}
公共字符串标题格式{get;set;}
公共字符串内容{get;set;}
}
公共类页面
{
公共字符串开始{get;set;}
公共int标签{get;set;}
}
公共类游标
{
公共字符串resultCount{get;set;}
公共列表页{get;set;}
公共字符串estimatedResultCount{get;set;}
public int currentPageIndex{get;set;}
公共字符串moresultsurl{get;set;}
公共字符串searchResultTime{get;set;}
}
公共类响应数据
{
公共列表结果{get;set;}
公共游标{get;set;}
}
公共类根对象
{
公共响应数据响应数据{get;set;}
公共对象响应详细信息{get;set;}
公共int responseStatus{get;set;}
}
您可以在这里生成类,这非常简单
假设您成功下载了json字符串,下面是作为控制台应用程序的代码。它使用json.net()
类程序
{
静态void Main(字符串[]参数)
{
var json=@“…json字符串…”;
var obj=JsonConvert.DeserializeObject(json);
Console.WriteLine(对象responseData.cursor.estimatedResultCount)
;
Console.ReadLine();
}
}
公开课成绩
{
公共字符串GsearchResultClass{get;set;}
公共字符串unescapedUrl{get;set;}
公共字符串url{get;set;}
公共字符串visibleUrl{get;set;}
公共字符串缓存URL{get;set;}
公共字符串标题{get;set;}
公共字符串标题格式{get;set;}
公共字符串内容{get;set;}
}
公共类页面
{
公共字符串开始{get;set;}
公共int标签{get;set;}
}
公共类游标
{
公共字符串resultCount{get;set;}
公共列表页{get;set;}
公共字符串estimatedResultCount{get;set;}
public int currentPageIndex{get;set;}
公共字符串moresultsurl{get;set;}
公共字符串searchResultTime{get;set;}
}
公共类响应数据
{
公共列表结果{get;set;}
公共游标{get;set;}
}
公共类根对象
{
公共响应数据响应数据{get;set;}
公共对象响应详细信息{get;set;}
公共int responseStatus{get;set;}
}
您可以在这里生成类,这非常简单
假设您成功下载了json字符串,下面是作为控制台应用程序的代码。它使用json.net()
类程序
{
静态void Main(字符串[]参数)
{
var json=@“…json字符串…”;
var obj=JsonConvert.DeserializeObject(json);
Console.WriteLine(对象responseData.cursor.estimatedResultCount)
;
Console.ReadLine();
}
}
公开课成绩
{
公共字符串GsearchResultClass{get;set;}
class Program
{
static void Main(string[] args)
{
var json = @".... json string....";
var obj = JsonConvert.DeserializeObject<RootObject>(json);
Console.WriteLine(obj.responseData.cursor.estimatedResultCount)
;
Console.ReadLine();
}
}
public class Result
{
public string GsearchResultClass { get; set; }
public string unescapedUrl { get; set; }
public string url { get; set; }
public string visibleUrl { get; set; }
public string cacheUrl { get; set; }
public string title { get; set; }
public string titleNoFormatting { get; set; }
public string content { get; set; }
}
public class Page
{
public string start { get; set; }
public int label { get; set; }
}
public class Cursor
{
public string resultCount { get; set; }
public List<Page> pages { get; set; }
public string estimatedResultCount { get; set; }
public int currentPageIndex { get; set; }
public string moreResultsUrl { get; set; }
public string searchResultTime { get; set; }
}
public class ResponseData
{
public List<Result> results { get; set; }
public Cursor cursor { get; set; }
}
public class RootObject
{
public ResponseData responseData { get; set; }
public object responseDetails { get; set; }
public int responseStatus { get; set; }
}