arrayscoldfusionlucee

doing a serializing a replace but the data i am expecting is not right


I have this function in a cfc which is doing me is returning me the months in an array

<cffunction name="getLocaleMonths">
        <cfargument name="sLanguage" required="true" default="1">
        <cfset arrData = []>
        <cfswitch expression="#sLanguage#">
             <cfcase value="10">
                 <cfset arrayAppend(arrData,'"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"')>
             </cfcase>
             <cfcase value="6">
                <cfset arrayAppend(arrData,'"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"')>
             </cfcase> 
             <cfcase value="13">
                <cfset arrayAppend(arrData,'"siječanj", "veljača", "ožujak", "travanj", "svibanj", "lipanj", "srpanj", "kolovoz", "rujan", "listopad", "studeni", "prosinac"')>
             </cfcase>  
             <cfcase value="1">
                <cfset arrayAppend(arrData,'"January","Febuary","March","April","May","June","July","August","September","October","November","December"')>
             </cfcase> 
</cfswitch> 
        <cfset results = Replace(serializeJSON(arrData),'\"',"",'all')>
        <cfreturn results>
     </cffunction>  

i am doing a serialize but i want my output to be as:

'["January","Febuary","March","April","May","June","July","August","September","October","November","December"]'

but it is coming like this

'["January,Febuary,March,April,May,June,July,August,September,October,November,December"]'

how can i fix it, i need some rereplace but my knowledge in regex is still growing

please see my updated code


Solution

  • You are not setting the array right. It need to look like this

      <cfset arrayAppend(arrData,["January","Febuary","March","April","May","June","July","August","September","October","November","December"], true)>
    

    Your other arrays have a similar issue.

    Note: You misspelled February