function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Abhishek KedariAbhishek Kedari 

Sending JSON object to servlet

Hi,

    I have JSON object created using JSONGenerator class. I want to pass this JSON object to my servlet in java.
    I want to send JSON object something like this http://www.xyz.com/basics/test.php(any extension here)?param=JSONObject.
     where JSONObject is json object.  and after that I want to write JSON parser inside my servlet (in java)

Can anyone help me, how to send JSON object to/from Salesforce and send/recievc JSON object in servlet.

Regards,
Abhishek
AshlekhAshlekh
Hi,

I think you need to visit below links which help you..

http://www.shivasoft.in/blog/salesforce/json-output-in-visualforce/

https://developer.salesforce.com/page/Getting_Started_with_Apex_JSON

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_json_jsongenerator.htm (https://developer.salesforce.com/page/Getting_Started_with_Apex_JSON)




IF it helps you than please mark it as a solution and ENJOY APEX (https://developer.salesforce.com/page/Getting_Started_with_Apex_JSON)



Abhishek KedariAbhishek Kedari
Thanks Ashlekh for the reply. I do know how to create JSON objects and how to parse the,. What I want to know is, how to embed that object into url.
e.g.
request = http://www.xyz.com/basics/test.php(any extension here)?param=JSONObject.
         Http h = new Http();
         HttpRequest req = new HttpRequest();
         req.setEndpoint(request);     
         req.setMethod('GET');
          HttpResponse res = h.send(req);

So how I can achive this ?
How to define header of http so that it will know that it contains JSON  object.


Thanks,
Abhishek
        
AshlekhAshlekh
Hi,

request.setHeader('Content-type','application/json');
request.setbody(JSONObject);


IF you want to send your json in parameter then may be URL lenght exceed. So you can set in your data in body.
Abhishek KedariAbhishek Kedari
Hi,

But how I can retrive this JSON object in my java servlet code ?
Can you write simple example ?
because request.body does not work.

Also How I can send request using json as a parameter in the url?

Thanks,
Abhishek