私は、既存のJSONファイルを読み込んでjsonオブジェクトとして返すwebapiを作成しようとしています。このため、Javascriptを使用してこのサイトにHTMLとしてデータを取り込むことができます。 https://pptlbhstorage.blob.core.windows.net/temperature/0_7622a22009224c78a46c0b2bc0a3fd82_1.jsonWebApiは既存のJSONファイルを読み込みます - C#
の場合: - Streamanalytics - 私はeventhubにイベントをログに記録temperatureloggerを持っているとして、JSONファイルが更新されるhttp://pptlbhweb.azurewebsites.net/
BLOBストレージ(アズール)ここで
にJSONとして保存されますがJSONファイルですあなたはこの方法でWebApiが返す有効なJSONオブジェクトを得ることができる最後に(これは私の考えである)最後に "]"を追加する必要があるJSONファイルを調べます。
私はすでにWebApiを作成しているので、URLを使用してデータを取得できます。 http://pptlbhwebapi.azurewebsites.net/api/temperature
修正:Global.assaxで
[System.Web.Http.Route("api/readandreturnjson")]
[System.Web.Http.HttpGet]
public async Task<IHttpActionResult> ReadAndReturnJsonAsync()
{
// object to return through the API (it'll be serialized by WebAPI)
object obj = null;
// WebClient used to download the JSON file
using (var wc = new WebClient())
{
var url =
"https://pptlbhstorage.blob.core.windows.net/temperature/0_7622a22009224c78a46c0b2bc0a3fd82_1.json";
// Used to hold and add a ']' to the downloaded JSON
StringBuilder builder = new StringBuilder();
builder.Append(await wc.DownloadStringTaskAsync(url));
builder.Append("]");
// Deserialize the now valid JSON into obj
obj = JsonConvert.DeserializeObject(builder.ToString());
}
// return the json with 200 Http status.
return Ok(obj);
}
:
があなたのAPIコントローラにこれを追加
例のためになる温度を取得するための同様の http://pptlbhwebapi.azurewebsites.net/api/test何か
GlobalConfiguration.Configuration.Formatters.Remove(GlobalConfiguration.Configuration.Formatters.XmlFormatter);
感謝を。私はこれを正しくやっていますか? – yellowborat
WebAPIを使用しているので、System.Web.Http.httpGetAttribute'を選択する必要があります。@yellowborat – Nasreddine
さて、これをhttpのtestControllerに入れますか? – yellowborat