Я получил ответ ниже JSON со своей страницы ASPX на мою страницу клиента. Теперь я хочу прочитать значения из него и хочу сгенерировать HTML
jsonData ={ "tnf": { "ci": [ {"atit": "Australia Pass", "img": "\/fr\/english\/Images\/EN_Fly_to_Rio_de_Janeiro_v1_185_tcm233-658117.jpg", "sop": "\/fr\/english\/destinations_offers\/special_offers\/mysite_visit_australia_pass\/mysite_visit_australia_pass.aspx" } ], "elt": [ {"t": "sfp", "value": "More special fares" } ], "f": [ { "a": [ {"c": "Hamburg", "p": "from GBP 469*", "pm": "id=744431#744431", "t": "sfp" }, {"c": "Dubai", "p": "from GBP 559*", "pm": "id=744432#744432", "t": "sfp" }, {"c": "Thiruvananthapuram", "p": "from GBP 559*", "pm": "id=744433#744433", "t": "sfp" }, {"c": "Johannesburg", "p": "from GBP 559*", "pm": "id=744434#744434", "t": "sfp" }, {"c": "Beijing", "p": "from GBP 1,780*", "pm": "id=744435#744435", "t": "sfp" }, {"c": "Guangzhou", "p": "from GBP 469", "pm": "pub=\/fr\/english&pageurl=\/IBE.aspx§ion=IBE&TID=SB&resultby=2&j=f&showpage=true&seldcity1=LHR&selacity1=JNB&selddate1=08%20Dec%2011&seladate1=09%20Dec%2011&bsp=Special+Fares+Widget&selcabinclass=0&showsearch=true", "t": "ffp" }, {"c": "Manila", "p": "from GBP 559*", "pm": "id=744437#744437", "t": "sfp" }, {"c": "Kuala Lumpur", "p": "from GBP 559*", "pm": "id=744438#744438", "t": "sfp" } ], "d": [ {"t": "sfp", "value": "From London Heathrow (LHR)" } ] } ], "nof": [ { "a": [ {"class": "bodyLink", "href": "\/sn\/english\/destinations_offers\/special_offers\/special_offers.aspx", "title": "Special Offers", "value": "Special Offers" } ], "value": [ "We don’t have any Special Fares at the moment. Please check again another time, or see our current", "." ] } ], "tc": "Conditions apply for each fare. Dublin commence from 9th January 2012.", "u": [ {"ffp": "\/SessionHandler.aspx", "ffpm": "pageurl=\/IBE.aspx&pub=\/fr\/english§ion=IBE&j=f&bsp=Special+Fares+Widget", "ot": "\/fr\/english\/destinations_offers\/special_offers\/mysite_visit_australia_pass\/mysite_visit_australia_pass.aspx", "sfp": "\/fr\/english\/destinations_offers\/special_offers\/special_fares\/special_fares.aspx" } ] }}
Пожалуйста, предложите, как я могу прочитать это, чтобы показать, что я могу легко добавить его в мои HTML
EDIT:
Это код Jquery, который я использую для получения этих значений:
$(document).ready(function() {
$('#btnSearch').click(function() {
var strInput = "";
var strSearchType = $('#ddnSearchType').val();
strInput = strInput + "?q=" + strSearchType;
var serviceReq = "http://localhost:2853/jsonproxy/jsonprxy.aspx";
$.ajax({
url: serviceReq + strInput,
dataType: "jsonp",
jsonpCallback: "processJsonData",
success: function(data, textStatus, jqXHR) {
// don't do anything here, since the processing happened in callback function
},
error: function(jqXHR, textStatus, errorThrown) { alert(textStatus); }
});
});
function processJsonData(data) {
alert(data);
$.each(data, function(i, tnf) {
alert(tnf.nof[0].a[0].href)
alert(tnf.elt[0].value)
alert(tnf.f[0].a.c);
$.each(tnf.f[0].a, function(j, adata) {
alert(adata.c);
alert(adata.pm)
});
});
}
});
Я вижу три переменные GET в инструменте HTTPFox,
q even
callback processJsonData
_ 1326530518049
Его ошибка синтаксического анализатора, а также функция "processJsonData" не распознаются.
и результат, который возвращается из моего CS, такой же, как указано выше.
Ниже приведен код, который я использую для получения JSON
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.Xml;
using System.IO;
using System.Runtime.Serialization.Json;
public partial class jsonProxy : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string strResult = "";
string strSearch = "";
try
{
if (Request.QueryString.Count != 0 && Request.QueryString["q"] != string.Empty)
{
strSearch = Request.QueryString["q"];
}
strResult = performSearch(strSearch);
}
catch
{
strResult = performSearch("");
}
Response.Clear(); //optional: if we've sent anything before
Response.ContentType = "text/html"; //must be 'text/xml'
Response.ContentEncoding = System.Text.Encoding.UTF8; //we'd like UTF-8
Response.Write("jsonData =" + strResult + "");
Response.End(); //optional: will end processing
}
private string performSearch(string strSearch)
{
string returnStr = "";
XmlDocument docXml = new XmlDocument();
docXml.Load("xml/SpecialFares.xml");
returnStr = XmlToJson.XmlToJSON(docXml);
return (returnStr);
}
}
Спасибо
С наилучшими пожеланиями,
MS