3

外部ドメインからjsonデータを取得する必要があります。webrequestを使用して、Webサイトから応答を取得しました。ここにコードがあります:

var search = umbraco.library.Request("search");
string Url = "http://ff.ss.dk/Suggest.ff?username=us&password=pass&channel=dk&format=JSON&query="+search;
WebRequest webRequest = WebRequest.Create(Url);
WebResponse response = webRequest.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);

このように私はこのような出力を取得しています

[{"hitCount":0、 "imageURL": ""、 "query": "Atrix h \ u00E5ndcreme Dobbeltvirkende / 100 Ml"、 "type": "productName"}、{"hitCount":0、 "imageURL": ""、 "query": "V \ u00E6gur Magneticisk attraction"、 "type": "productName"}、{"hitCount":0、 "imageURL": ""、 "query": "Bic kuglepen Atlantis、bl \ u00E5 "、" type ":" productName "}、{" hitCount ":0、" imageURL ":" "、" query ":" Laminering AT1256 31cm x30m A3 "、" type ":" productName "}]

この出力データをJSONオブジェクト形式で取得したいので、これをJavaスクリプト関数で使用できます。ストリームリーダー関数を使用してデータを取得したため、出力データが不適切な形式になっていると思います。この問題を解決するためのアイデアはありますか?

4

2 に答える 2

7

このデータは、jQuery.parseJSONを使用してjson形式に変換できます。

 var obj = JSON.parse(data);

次に、次のようなデータにアクセスできます

 obj[0].id

ありがとうございます。

于 2012-08-10T05:56:53.340 に答える
0

配列名指定子が欠落しているようです。たとえば、これは機能します。

{arrayName:[{"hitCount":0,"imageURL":"","query":"Atrix h\u00E5ndcreme Dobbeltvirkende /100 Ml","type":"productName"},{"hitCount":0,"imageURL":"","query":"V\u00E6gur magnetisk attraction","type":"productName"},{"hitCount":0,"imageURL":"","query":"Bic kuglepen Atlantis , bl\u00E5","type":"productName"},{"hitCount":0,"imageURL":"","query":"Laminering AT1256 31cm x30m A3","type":"productName"}]}
于 2012-08-07T12:36:46.880 に答える