Forum Discussion
NicoB
12 years agoLithium Alumni (Retired)
Hi Gursimrat
You should use http.client.request.json() in order to parse your json response into a Freemarker hashset:
Thanks,
Nico
Gursimrat
12 years agoLeader
This is not working when I user .json()
.get() is Working
<#assign search_query = http.request.parameters.name.get("search_query","optimizely") />
<#assign response = http.client.request("http://community/collection1/select?q=${search_query}&wt=json&indent=true").get() />
<#if response.hasError>
${response.error.message}
<#else>
${response.content}
</#if>
.json() is NOT Working
<#assign search_query = http.request.parameters.name.get("search_query","optimizely") />
<#assign response = http.client.request("http://community/collection1/select?q=${search_query}&wt=json&indent=true").json() />
<#if response.hasError>
${response.error.message}
<#else>
${response.content}
</#if>
Error is as below:
{ "error":"
FreeMarker template error:
The following has evaluated to null or missing:
==> response.hasError [in template "zendesksearchapiurl.ftl" at line 4, column 6]
Tip: If the failing expression is known to be legally null/missing, either specify a default value with myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthessis: (myOptionVar.foo)!myDefault, (myOptionVar.foo)??
The failing instruction (FTL stack trace):
----------
==> #if response.hasError [in template "zendesksearchapiurl.ftl" at line 4, column 1]
----------