我正在尝试从Google AJAX Search API解析一些JSON数据.我有这个URL,我想将其分解,以便显示结果.我目前已经编写了这段代码,但我对于下一步该做什么感到非常遗憾,尽管有很多例子都有简化的JSON字符串.
作为C#和.NET的新手,我一直努力为我的ASP.NET页面获得真正的文本输出,所以我一直建议尝试JSON.NET.任何人都可以指出我正确的方向只是简单地编写一些代码,这些代码将从Google AJAX Search API中获取JSON并将其打印到屏幕上吗?
编辑:全部固定!所有结果都很好.再次感谢Dreas Grech!
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ServiceModel.Web;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GoogleSearchResults g1 = new GoogleSearchResults();
const string json = @"{""responseData"": {""results"":[{""GsearchResultClass"":""GwebSearch"",""unescapedUrl"":""http://www.cheese.com/"",""url"":""http://www.cheese.com/"",""visibleUrl"":""www.cheese.com"",""cacheUrl"":""http://www.google.com/search?q\u003dcache:bkg1gwNt8u4J:www.cheese.com"",""title"":""\u003cb\u003eCHEESE\u003c/b\u003e.COM - All about \u003cb\u003echeese\u003c/b\u003e!."",""titleNoFormatting"":""CHEESE.COM - All about cheese!."",""content"":""\u003cb\u003eCheese\u003c/b\u003e - everything you want to know …Run Code Online (Sandbox Code Playgroud) 我尝试使用http://www.codeplex.com/Json从json对象中提取值.
我使用imdbapi.com,他们像这样返回json:
{"Title": "Star Wars", "Year": "1977", "Rated", "PG", "Released", "25 May 1977", "Genre", "Action, Adventure, Fantasy, Sci-Fi "" Director ":" George Lucas "," Writer "," George Lucas "," Actors ":" Mark Hamill, Harrison Ford, Carrie Fisher, Alec Guinness, "" Plot ":" Luke Skywalker leaves his home planet, teams up With Other Rebels, and Tries to save Princess Leia from the evil clutch of Darth hrs 1 min "," Rating ":" 8.8 "," Votes ":" 397318 "," ID …Run Code Online (Sandbox Code Playgroud)