Welcome Guest, Not a member yet? Register   Sign In
need help formating JSON
#1

[eluser]dottedquad[/eluser]
Hello all,
My current code:

Code:
function get_location_list()
        {
            $location_list = array();
            
            $query = $this->db->query('SELECT id, location FROM location');
            
            foreach ($query->result_array() as $row)
            {
                $value = $row['id'];
                $text = $row['location'];
                
                $location_list['result'][$value] = $text;    
            }
            echo json_encode($location_list);
            
            //return ;
                                        
        }
My JSON is formatted as such:
{"result":{"1":"chickenpen 1","2":"chickenpen 2","3":"chickenpen 3","4":"chickenpen 4"}}

It should be formatted like:
Code:
{"results":[  
     {"id":1,"name":"chickenpen 1"},  
     {"id":2,"name":"chickenpen 2"},  
     {...} // more results here...  
]}

How do I get my JSON string to be formatted like the above sample?

-Thank You,
Rich


Messages In This Thread
need help formating JSON - by El Forum - 08-04-2010, 08:47 PM
need help formating JSON - by El Forum - 08-04-2010, 09:06 PM
need help formating JSON - by El Forum - 08-04-2010, 09:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB