This is my updated class

public class ConvertCurrencyWS

public class ResponsWS

String id;
String quote;


public void getConvertCurrency()

Http h = new Http();

HttpRequest req = new HttpRequest();

HttpResponse resp = h.send(req);
//return  resp.getBody();
String resstring = resp.getBody();
ResponsWS r = (ResponsWS)JSON.deserialize(resstring,ResponsWS.class);

System.debug('Response is '+resstring);
System.debug('The quote is '+r.Id+'   '+r.quote);



Q :

It works but the json serializing is not happening somehow as because the second debug returns as "null" for both the id & quote as shown below.

Can someone tell me why both the values are returning as null ?

enter image description here

  • It looks like a certificate issue for me pls make sure on this. Sep 6 '15 at 6:34
  • @SalesforceLearner You are right...I have found out that the particular API needs certificate...I am now trying with another API and have encountered another issue..can you see ?...I have updated the question now
    – Varun
    Sep 6 '15 at 6:52
  • Updated the post
    – Varun
    Sep 6 '15 at 7:00

You could make your own class that you deserialize it into:

public class MyWebserviceResponse{

    public string type;
    public ValueClass value;

    public class ValueClass{
        public integer id;
        public string quote;

  • @Martin...Thanks But even after deserializing I am getting null in the class's value...please take a look at my update
    – Varun
    Sep 6 '15 at 7:24
  • @ZenSeeker I think the problem is that the class variables are not visible when you are deserializing the JSON string. Try making them public.
    – martin
    Sep 6 '15 at 7:31
  • Hmm..I tried them as public but still no luck :(
    – Varun
    Sep 6 '15 at 7:36
  • @ZenSeeker I figured it out, we need to have this as a subclass. I'll update my answer.
    – martin
    Sep 6 '15 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.