You need to sign in to do that
Don't have an account?
Vishalg89
read rhe JSON from POST URL
Hi all,
I need to create a REST service URL in apex, through which a PHP application POST a JSON object to me and then I need to read the JSON from that. please give any help about this.
My sample code:
@RestResource(urlMapping='/myapp/')
global with sharing class myController{
@HttpPOST
/* This is method is responsible for reading the JSON data*/
global static String doPOST()
{
////////////////////// read JSON /////////////////////////////
}
please help me regarding this problem.
MyWrapperClass is just some generic class that contains the fields you are receiving from the PHP script. You could also use the JSONParser object as well, or deserialize into a map, etc. You should probably read the documentation for JSON parsing so you have a better idea of how you'd like to structure your code.
All Answers
Hi Vishal, If you are able to get URL through REST API you should use Json Parser Method to read data.
But how to read JSON object from URL? another application hitting my URL and POST the JSON object? I dont know, how to read that?
MyWrapperClass is just some generic class that contains the fields you are receiving from the PHP script. You could also use the JSONParser object as well, or deserialize into a map, etc. You should probably read the documentation for JSON parsing so you have a better idea of how you'd like to structure your code.
thanks very much...
I applied the code as you suggested. I am posting JSON object from PHP code and but i am not getting anything in "req.requestBody" It is empty.
Hi
You can pass url by EndPoint.
You will receive input through HTTPResponse. Try my running code.
thanks Varun, but looking into your code, it seems that you r hitting the URL of another application.. but in my case, a PHP application hittinf my REST API URL and POST a JSON to me and I am not able to read that!!!!
If you are getting JSON you should go through this link
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_jsonparser.htm
thanks to all.. solution code worked for me...