2

When ever i click on Upload Intent then works perfectly and i get response but when i click on status i get this json error, This is my VF,

<apex:commandButton action="{!upload}" value="Upload Intent"  reRender="output" id="upload" />   
<apex:commandButton action="{!Train}" value="Train Dataset" reRender="output1" id="train" /> 
<apex:outputText style="top: 50px;margin-left: 55px;font-size: x-large;" rendered="true" id="output" value="{!probability }"></apex:outputText>
<apex:outputText style="top: 50px;margin-left: 55px;font-size: x-large;" rendered="true" id="output1" value="{!modelid}"></apex:outputText>

This is my Class.

public void Train() {
 string name = 'Weather Intent Model';
 tokenkey = eaccess.getAccessToken();
 modelid= eaccess.getstatus(name, tokenkey, datasetid);
 }

eaccess Class

 public static statusresponse getstatus(string name ,string token,integer datasetid){
        HttpRequest req = new HttpRequest();
        req .setMethod( 'POST');
        req .setEndpoint('https://api.einstein.ai/v2/language/train');
        req .setHeader( 'Authorization', 'Bearer ' + token );
        req .setHeader( 'Cache-Control', 'no-cache' );
        req .setHeader( 'Content-Type', HttpFormBuilder.GetContentType() );

        req.setTimeout( 120000 );
        system.debug( 'name '+ name+ ' datasetId  '+ datasetId );
        String mutipartFormData = '';
        mutipartFormData += HttpFormBuilder.WriteBoundary();
        mutipartFormData += HttpFormBuilder.WriteBodyParameter( 'name', name );
        mutipartFormData += HttpFormBuilder.WriteBoundary();
        mutipartFormData += HttpFormBuilder.WriteBodyParameter( 'datasetId',String.valueOf(datasetId ) );
        mutipartFormData += HttpFormBuilder.WriteBoundary( NULL );

        Blob formBlob = EncodingUtil.base64Decode( mutipartFormData );

        req.setBodyAsBlob( formBlob );

        Http http = new Http();
        system.debug( formBlob );
        HTTPResponse response= http.send( req);
        system.debug(response.getBody());

                statusresponse statusres= (statusresponse ) System.JSON.deserialize(response.getBody(), statusresponse .class);

         statusresponse  model= statusres;
         getmodeldetails(token,model);
        return model;

    }

I GET ERROR FROM THIS LINE

statusresponse statusres= (statusresponse ) System.JSON.deserialize(response.getBody(), statusresponse .class);

My Response Class

public class statusresponse{
    public Integer datasetId;   //1023017
    public Integer datasetVersionId;    //0
    public String name; //Weather Intent Model
    public String status;   //QUEUED
    public Integer progress;    //0
    public String createdAt;    //2017-11-23T18:16:07.000+0000
    public String updatedAt;    //2017-11-23T18:16:07.000+0000
    public Integer learningRate;    //0
    public Integer epochs;  //0
    public Integer queuePosition;   //1
    public String objects;   //training
    public String modelId;  //O6OQTXTPN4GFNHO4WDY5VKNGKY
    public cls_trainParams trainParams;
    public cls_trainStats trainStats;
    public String modelType;    //text-intent
    class cls_trainParams {
    }
    class cls_trainStats {
    }
    public static statusresponse parse(String json){
        return (statusresponse) System.JSON.deserialize(json, statusresponse.class);
    }


}

Debug log Error

FATAL_ERROR System.JSONException: For input string: "0.0" at [line:1, column:189]
 FATAL_ERROR Class.System.JSON.deserialize: line 15, column 1
 FATAL_ERROR Class.einsteinaccess.getstatus: line 144, column 1
 FATAL_ERROR Class.einsteinsentiment.Train: line 44, column 1

This is my Json:

{"datasetId":1022045,"datasetVersionId":0,"name":"Weather Intent Model","status":"QUEUED","progress":0,"createdAt":"2017-11-23T20:11:55.000+0000","updatedAt":"2017-11-23T20:11:55.000+0000","learningRate":0.0,"epochs":0,"queuePosition":1,"object":"training","modelId":"TGQHXXMOK363IYQ6OXJC6ENMME","trainParams":null,"trainStats":null,"modelType":"text-intent"}
5
  • It looks like you're trying to put a Decimal value in to an Integer. What happens if you change your class to use Decimal values instead?
    – sfdcfox
    Commented Nov 23, 2017 at 19:42
  • Its integer, if its a decimal then it would have returned .0 in all the places.
    – kishore
    Commented Nov 23, 2017 at 19:55
  • How do we know the data type? You didn't actually share your JSON with us. Point is, the parser expected type X, but the JSON has type Y.
    – sfdcfox
    Commented Nov 23, 2017 at 20:02
  • Uploaded my JSON response too
    – kishore
    Commented Nov 23, 2017 at 20:13
  • Even i tested 30+ times in all the way its because of the statusresponse statusres= (statusresponse ) System.JSON.deserialize(response.getBody(), statusresponse .class);
    – kishore
    Commented Nov 23, 2017 at 20:26

1 Answer 1

7
public Integer learningRate; //0

In your JSON, it appears as a Decimal value. Change the code as follows:

public Decimal learningRate; //0.0
2
  • I have question how did u know it was a decimal? because i have many responses to work on
    – kishore
    Commented Nov 23, 2017 at 20:33
  • @kishore consider using json2apex to help you out. As a general case, JSON supports only about six types. Integer, decimal, Boolean, date, date time, and string (plus arrays and objects). Check out the JSON specs online to learn more.
    – sfdcfox
    Commented Nov 23, 2017 at 20:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .