我有QueryToJSON的代码
<cffunction name="queryToJSON" returntype="string" access="public" output="yes">
<cfargument name="q" type="query" required="yes" />
<cfset var o=ArrayNew(1)>
<cfset var i=0>
<cfset var r=0>
<cfloop query="Arguments.q">
<cfset r=Currentrow>
<cfloop index="i" list="#LCase(Arguments.q.columnList)#">
<cfset o[r][i]=Evaluate(i)>
</cfloop>
</cfloop>
<cfreturn SerializeJSON(o)>
</cffunction>
效果很好。唯一的问题是key: value
对。 value
并不总是用双引号括起来。我希望所有的值都用双引号括起来。
我可以改变什么来实现这一目标?
示例:所需结果:
{"zoho_item_name": "Shipping Charges",
"id": "128177000000051618",
"tms_name": "***Ship My book to me before class***",
"sku": "",
"description": "Shipping",
"rate": "6.57",
"Account": "Shipping Fees",
"taxable": "true",
"ExemptionReason": "",
"Source": "2",
"ReferenceId": "",
"LastSyncTime": "",
"Status": "Active",
"Usageunit": "",
"PurchaseRate": "0.00",
"PurchaseAccount": "",
"PurchaseDescription": "",
"InventoryAccount": "",
"ReorderPoint": "",
"Vendor": "",
"InitialStock": "",
"InitialStockRate": "",
"ItemType": "Sales"
}
实际结果:
{
"initialstockrate": "",
"inventoryaccount": "",
"usageunit": "",
"rate": 7.65,
"tms_name": "***Ship my item(s) to me before class***",
"taxable": true,
"description": "Shipping",
"sku": "",
"purchaseaccount": "",
"purchaserate": 0.00,
"status": "Active",
"account": "Shipping Fees",
"lastsynctime": "",
"initialstock": "",
"zoho_item_name": "Shipping Charges",
"source": 2,
"exemptionreason": "",
"id": 128177000000051618,
"reorderpoint": "",
"referenceid": "",
"vendor": "",
"itemtype": "Sales",
"purchasedescription": ""
}
答案 0 :(得分:0)
通常来说,布尔值和数字不应该是字符串。这首先消除了真/假和数字的全部要点。但是,您可以使用ToString
解决此问题。
<cfset o[r][i]= ToString(Evaluate(i))>