We help IT Professionals succeed at work.

Json - How do remove chars from a json qry output

279 Views
Last Modified: 2012-03-01
I had a previous issue that several people suggested I use json to resolve.  Was not familiar with it nor was the js programmer an expert with it, so I didn't pursue it  with a previous project.  I have started working with json a bit and found an issues I can't resolve:

I am using  code like this to spit about and array of data:
<?php
 $requiredFieldsArray = array();
    $results = mysql_query("select account_id, display_name, id from field 
where account_id = $holdAcctID and required_flag = 1");
    while($result = mysql_fetch_assoc($results)) 
        {
        $requiredFieldsArray[] = $result;
    }
?>
<script language="javascript">
    var requiredFieldsPRS = <?php echo "new Array(". json_encode($requiredFieldsArray).")"; ?>;
</script>
}

Open in new window


It outputs this:
 var requiedFieldsPRS = new Array([{"account_id":"3","display_name":"Project Requested By","id":"15"},{"account_id":"3","display_name":"Project Title","id":"18"},{"account_id":"3","display_name":"Project Type","id":"19"},{"account_id":"3","display_name":"Banner Details","id":"20"},{"account_id":"3","display_name":"Email to Me","id":"2910"}]);;

Open in new window


In my code how can I remove the "[" and "]" from the beginning and end of the array, so it will appear like this?
 var requiedFieldsPRS = new Array({"account_id":"3","display_name":"Project Requested By","id":"15"},{"account_id":"3","display_name":"Project Title","id":"18"},{"account_id":"3","display_name":"Project Type","id":"19"},{"account_id":"3","display_name":"Banner Details","id":"20"},{"account_id":"3","display_name":"Email to Me","id":"2910"});

Open in new window

Note: The opening and closing brackets are gone in the above output.
Comment
Watch Question

Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.