當前查詢Oracle數據庫的Web API正在以下面的格式返回JSON中的結果。ASP.NET Web API將JSON作爲對象返回
[{"CATEGORY":"Internal Study","SESSION_NUMBER":7,"SESSION_START_DATE":"2015-02-13T00:00:00","SESSION_START_TIME":"2015-02-13T10:33:59.288394"}]
下面是我們使用
public class SampleController : ApiController
{
public HttpResponseMessage Getdetails([FromUri] string[] id)
{
using (OracleConnection dbconn = new OracleConnection("DATA SOURCE=J;PASSWORD=C;PERSIST SECURITY INFO=True;USER ID=T"))
{
var inconditions = id.Distinct().ToArray();
var srtcon = string.Join(",", inconditions);
DataSet userDataset = new DataSet();
var strQuery = @"SELECT * from STCD_PRIO_CATEGORY where STPR_STUDY.STD_REF IN(" + srtcon + ")";
OracleCommand selectCommand = new OracleCommand(strQuery, dbconn);
OracleDataAdapter adapter = new OracleDataAdapter(selectCommand);
DataTable selectResults = new DataTable();
adapter.Fill(selectResults);
var response = Request.CreateResponse(HttpStatusCode.OK, selectResults,MediaTypeHeaderValue.Parse("application/json"));
ContentDispositionHeaderValue contentDisposition = null;
if (ContentDispositionHeaderValue.TryParse("inline; filename=ProvantisStudyData.json", out contentDisposition))
{
response.Content.Headers.ContentDisposition = contentDisposition;
}
return response;
}
}
的代碼,但它有消耗文件腳本中的客戶說,JSON結構是一個數組,而不是一個對象是一個安全漏洞。
{"data":[{"CATEGORY":"Internal Study","SESSION_NUMBER":7,"SESSION_START_DATE":"2015-02-13T00:00:00","SESSION_START_TIME":"2015-02-13T10:33:59.288394"}]}
我是新來這個JSON結構,不知道我們將如何處理返回的數據作爲JSON文件中的對象
你是什麼意思的「客戶」在這裏?誰說這是一個安全漏洞? – DavidG
我看到最上面的一個是現在返回的,最下面的是你想要的:P安全漏洞是頂級JSON數組可以被劫持,因爲它是一個有效的JavaScript腳本,其中作爲JSON對象不是。 – starlight54
@ starlight54你確定嗎? http://stackoverflow.com/questions/16289894/is-json-hijacking-still-an-issue-in-modern-browsers – DavidG