我尝试使用JavaScript代码从以下网址获取一些数据:
http://data.cityofnewyork.us/resource/erm2-nwe9.json
这是我构建查询的方式:
//data URL variables
var start_date = '2013-08-01'; //YYYY-MM-DD
var end_date = '2013-08-08'; //YYYY-MM-DD
var c_type = 'Noise'; // Complaint Type
// Build the data URL
var URL = "http://data.cityofnewyork.us/resource/erm2-nwe9.json"; // API Access Endpoint
URL += "?";
URL += "$where=";
URL += "(latitude IS NOT NULL)";
URL += " AND ";
URL += "(complaint_type='" + c_type + "')";
URL += " AND ";
URL += "(created_date>='" + start_date + "') AND (created_date<='" + end_date + "')";
URL += "&$group=complaint_type,descriptor,latitude,longitude";
URL += "&$select=descriptor,latitude,longitude,complaint_type";
URL = encodeURI(URL);
到目前为止我是如何测试它的:
$.getJSON(URL, function(data)
{
console.log(data)
});
现在它工作正常,但我应该考虑任何包含单个世界的投诉类型(&#34; Noise&#34;):
URL += "(complaint_type LIKE '%" + c_type + "%')";
编码的URL(似乎没问题):
http://data.cityofnewyork.us/resource/erm2-nwe9.json $其中=(纬度%图20是%20NOT%20NULL)%20于是%20?(complaint_type%20LIKE%20&#39;%25Noise%25&#39)%20于是%20(CREATED_DATE%3E =&#39; 2013年8月1日&#39)%20于是%20(CREATED_DATE%3C =&#39; 2013年8月8日&#39;)及$组= complaint_type,描述符,纬度,经度和安培; $选择=描述符,纬度,经度,complaint_type
错误:
{
"code" : "query.compiler.malformed",
"error" : true,
"message" : "Error, could not parse SoQL query \"select descriptor,latitude,longitude,complaint_type from #erm2-nwe9 where (latitude IS NOT NULL) AND (complaint_type LIKE '%Noise%') AND (created_date>='2013-08-01') AND (created_date<='2013-08-08') group by complaint_type,descriptor,latitude,longitude\"",
"data" : {
"query" : "select descriptor,latitude,longitude,complaint_type from #erm2-nwe9 where (latitude IS NOT NULL) AND (complaint_type LIKE '%Noise%') AND (created_date>='2013-08-01') AND (created_date<='2013-08-08') group by complaint_type,descriptor,latitude,longitude"
}
}
documentation似乎可以使用LIKE,但我无法使其工作。
我不知道该怎么做。
答案 0 :(得分:1)
我刚刚弄清楚它是如何工作的,似乎它在条件中不接受百分号符号'%',它应该以反斜杠开头(或者它只是斜线,无论如何)。
所以这是使用'like'语句的有效URL:
http://data.cityofnewyork.us/resource/erm2-nwe9.json?$where=(latitude%20IS%20NOT%20NULL)%20AND%20(complaint_type%20like%20%27\%Noise\%%27)%20AND%20(created_date%3E=%272013-08-01%27)%20AND%20(created_date%3C=%272013-08-08%27)&$group=complaint_type,descriptor,latitude,longitude&$select=descriptor,latitude,longitude,complaint_type
代码中的相应行:
URL += "(complaint_type LIKE '\\%" + c_type + "\\%')";
让我知道它是否有效,并且抱歉没有按时回复,我真的没有使用Salesforce和SOQL的经验。但是多亏了你,我还有另一个新的空间可以探索:)