Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X
Hi, I have a service that outputs a JSON. The service is as simple as
var result = {
"ReturnCode": 0,
"Message": ""
};
However, when I called the service using POSTMAN, it returns
I tried parseInt("0") to output integer for ReturnCode yet it doesn't work. How to convert the JSON format from number to integer?
Thanks.
Do you need that for calculation purposes or just display purposes? If it’s just for display, you could return it as a string instead of a number. If it’s for a calculation, the decimal shouldn’t matter too much; and if it’s for some logical ‘if, while, etc...” test and you’re worried about testing an int vs [float,double,numeric,etc], then perhaps you can use whatever program you’re calling the service in to handle the type-casting of that number. Hope that helps!
Thank you for your response. I think I can't do that because I want to integrate with the other 3rd party software which I can't modify the function to cast the data type. I understand about casting in Thingworx or even if it is just for display. However, I need this to integrate as an integer is a compulsory data type.
What client are you seeing the decimal in? I did a quick test in Chrome ARC and I'm only getting integers:
{
}
ThingWorx service code:
var res = {};
var code = 0;
res.rawCode = code;
res.parsedCode = parseInt(code);
res.fixedCode = code.toFixed();
var result = res;
Hi @nmilleson , I am using POSTMAN. This is the service that I updated using your code.
This is the result returned to the POSTMAN when I invoke the service.
Perhaps that's just something that Postman does. Does it throw an error in your 3rd party software?
Yes, it does. This is the error log from the software.
As you can see that the software is expecting an integer. However, somehow it detects the ReturnCode data type as a string even though I stated that it is an integer. Any ideas on this?