У тебя хорошее начало. Содержимое вашей переменной meetlist
содержит массив структур. Так что все, что вам нужно сделать, это l oop через массив структур и выполнить вставку для каждого элемента массива. Построение существующего кода, вот что вам нужно.
Некоторые улучшения в этом примере кода должны включать блоки <cftry>
, <cfcatch>
и <cftransaction>
, но этого должно быть достаточно для начала работы.
<cfset urlAddress="http://www.tectrics.com/english/map/localjson.cfm">
<cfhttp url="#urlAddress#" method="GET" resolveurl="Yes" throwOnError="Yes"/>
<cfset meetlist=DeserializeJSON(CFHTTP.FileContent)>
<cfdump var="#meetlist#"> <!--- Remove this dump --->
<cfloop array="#meetlist#" index="i">
<!--- each loop iteration will contain a struct called "i". Do an insert for each iteration of the loop --->
<cfquery datasource="mydatasource">
INSERT INTO table_name (
attended,
childcare,
childfriend,
...
)
VALUES (
<cfqueryparam value="#i.attended#" cfsqltype="cf_sql_integer">, <!--- use the appropriate cfsqltype that matches the column's data type --->
<cfqueryparam value="#i.childcare#" cfsqltype="cf_sql_varchar">, <!--- use the appropriate cfsqltype that matches the column's data type --->
<cfqueryparam value="#i.childfriend#" cfsqltype="cf_sql_varchar">, <!--- use the appropriate cfsqltype that matches the column's data type --->
...
)
</cfquery>
</cfloop>