1 Reply Latest reply on Feb 27, 2009 12:03 PM by w_o_t_boy

    Formatting JSON

    ClayD Level 1
      I am really frustrated right now. I have a method with the return format as JSON. All fine and good, but the ouptut looks like this:

      [{"KEY":"Grindhouse Trash 03 How to Make a Dirty Movie","STYLELIST1":"|\\| |_| |_ |_","STYLELIST2":"|\\| |_| |_ |_","DISPLAYTYPEID":0,"PRODUCTSEQUENCE":"|\\| |_| |_ |_","DISPLAYPRODUCTSKUS":[{"STOCKSTATUSID":1,"STARTSHIPDATE":"10\/11.....and so on.

      I somehow need to change that into some variables, the product name and the product id that i will return to the page. I have no idea how to do this. Can someone help me please? Below is my CFC code and my return code on the page.

      CFC Code......

      <cffunction name="search" access="remote" returnformat="json" output="false" hint="affiliates enter in a string, we bring them back the product info">
      <cfargument name="searchString" required="yes"/>
      var resultFilter=null;
      var query=null;
      var result=null;

      resultFilter = CreateObject("component", "COM.tlavideo.results.Filter");

      query=component("COM.tlavideo.results.Query").init(narrowingFilter=resultfilter, searchstring=arguments.searchstring, searchgroup="product");
      result=query.getResult(resultgroup="product", pagingneeded="false", pageNum="1", pageSize="50");

      return serializeJSON(result.get("productresults"));


      CODE ON PAGE.....

      <cfif structkeyexists(form, "search")>
      <cfset affiliatessearch=createobject("component", "affiliates.affiliatestextsearch")>
      <cfset result=affiliatessearch.search(form.search)>
        • 1. Re: Formatting JSON
          The stuff it returns is a Javascript object. You should be able to type something like the following to get it into the browser's memory. Then you have to figure out how to loop over it using Javascript and get the data you want out.