I have the following code in a codeigniter REST app (built using: https://github.com/chriskacerguis/codeigniter-restserver)
public function fullname_get()
{
$
Try this
$fullname = array("fname"=>"john", "lname"=>"doe");
$this->response($fullname, 200);//it sends data json format. You don't need to json encode it
You got that response because your data is json encoded twice
It is legit JSON - and you didn't write a test ;)
{
"fname": "john",
"lname": "doe"
}
Please see the demo over at http://ideone.com/5IW1Ef
The class you are using does magical things:
$this->response($this->db->get('books')->result(), 200);
and based on the format specified on the URL the response data is converted to JSON. You don't have to do the JSON encoding.
Please read the examples provides here https://github.com/chriskacerguis/codeigniter-restserver#responses
$fullname = array("fname"=>"john", "lname"=>"doe");
$this->response($fullname, 200);
http://code.tutsplus.com/tutorials/working-with-restful-services-in-codeigniter-2--net-8814
You have to strip slashes, use this stripslashes(json_encode($fullname)). Full code mention below:
public function fullname_get()
{
$fullname = array("fname"=>"john", "lname"=>"doe");
$data["json"] = stripslashes(json_encode($fullname));
$this->response($data["json"], 200);
}
I hope this will solve your issue.