0

I am building an API using Codeigniter and Phils RESTServer. I want to send a bounch of email addresses to the API (best in JSON format).

How can I do this? How can I "receive" and "use" the JSON object that is sent to the server?

Right now I can send and receive parameters like this:

[email protected]

and I receive and use them like this:

$this->post('email')

I want to send and receive in this format instead

{"email":"[email protected]"}

How can I achieve this and how can I use the object?

UPDATE: I at least need to be able to send a normal array to the RESTserver.

Thankful for all input!

2 Answers 2

1

There is an output class in codeigniter. For json encode, you can use this:

 $contents = $this->output
                  ->set_content_type('application/json')
                  ->set_output(json_encode(array('email' => '[email protected]')));

 echo $contents;//{"email":"[email protected]"}
Sign up to request clarification or add additional context in comments.

Comments

0

How about posting the JSON string to the controller and then using json_decode() to extract the data out if it?

$data = json_decode($this->post('json'));
echo $data['email'];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.