Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 888

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
For more information about these functions and examples, see the CFML Reference.
The following example shows how to use ColdFusion JSON functions in a non-Ajax application. It does a Yahoo
search for references to "ColdFusion Ajax" and displays these results:
• The total number of web pages found
• The titles and summaries of the (by default 10) returned results. The title is a link to the web pageURL.
<!--- Send an http request to the Yahoo Web Search Service. --->
<cfhttp
url='http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=
"ColdFusion Ajax"&output=json'>
<!--- The result is a JSON-formatted string that represents a structure.
Convert it to a ColdFusion structure. --->
<cfset myJSON=DeserializeJSON(#cfhttp.FileContent#)>
<!--- Display the results. --->
<cfoutput>
<h1>Results of search for "ColdFusion 9"</h1>
<p>There were #myJSON.ResultSet.totalResultsAvailable# Entries.<br>
Here are the first #myJSON.ResultSet.totalResultsReturned#.</p>
<cfloop index="i" from="1" to="#myJSON.ResultSet.totalResultsReturned#">
<h3><a href="#myJSON.ResultSet.Result[i].URL#">
#myJSON.ResultSet.Result[i].Title#</a></h3>
#myJSON.ResultSet.Result[i].Summary#
</cfloop>
</cfoutput>
Serialization of numeric values
Note: To use this feature, you must install ColdFusion 9 Update 1.
In the previous releases (including ColdFusion 9), serializing an integer using serializeJSON, converts the number to
a double. For example,
SerializeJSON (123)
In ColdFusion 9.0.1, the integer is retained in its original format but enclosed within quotes. That is,
returns
. This is applicable only to positive integers.
(123)
"123"
The following table gives more examples:
Input
10
012
10.25
10.25E5
10.25E-5
-10
-10.25
Note: To remove the quotes in the returned value, for positive integers and integers within quotes, set the jvm argument
json.numberasdouble totrue
json.numberasdouble=true
returns
123.0
Serialized JSON
"10"
"012"
"10.25"
"1025000.0"
"1.025E-4"
"-10.0"
"-10.25"
. However, negative integers such as -10 will still be serialized to "-10.0" even if
.
Last updated 1/20/2012
.
883
SerializeJSON

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents