I have a JSON response from REST API shown below, "total_tickets": "53" which is in the form of String type but I'm trying to convert to int type to do a conditional check using Logic App if greater than 50 then..run some blocks else other blocks. how to convert it to integer to make it for in the Condition block ?
JSON REST Response is something like this
There is a int function to get integer version for a string. Check this.
And in the logic app, you could use it like the below pic shows.
Related
I'm trying to compare to strings in a function to be able to do stuff if it's true. However, for some reason the two strings I'm comparing are never equal to eachother.
I am creating a new string in a function, getting data from a Json and then comparing that string with another string in another class. This doesn't work for some reason. The Debug shows that both strings are equal, but the if-statement returns false.
I created two other string variables (hello & hello2) with the same value ("Hello") and this time it's comparing correctly.
Check the images below. What am I doing wrong?
As you can see in the console, both strings have the same value:
Image 1. Here's where I create the string (zoneId).
Image 2. Further down in the same function, same for-loop.
Here's where I'm trying to compare the string created in this function with another string from another class.
Image 3. As you can see in the console it's looping through the jsonArray. But it's returning false even though it's clear that both strings have the same value.
Image 4 and 5. Here I am testing with two other strings inside the function and they are working fine.
Does it has something to do calling a string from another class?
Here's how my other string in userInfo is set up:
public string userID { get; private set; }
In Image 3, is there an additional space before the second 2?
How are you processing Main.Instance.userInfo.zoneID?
You need to use string.Equals for string comparison instead of operator == or !=.
Are string.Equals() and == operator really same?
I'm using Angular 4 and a Spring service that I throws an exception with the message being the toString of a List of messages. The problem is that when I receive the exception response and extract the message, instead of being treated like an Array of strings, it's treated as a single string in the format of: "[message 1, message 2]"
Is there a way in typescript to easily convert this String into an array of strings? I tried instantiating a new Array with the string like: new Array(errorResponse.error.message); but that didn't really work.
It should working for you:
var messages = message.substring(1, message.length-1).split(", ");
Fiddle with a function, which doing this is available here.
It works with JSON.Parse("[message 1, message 2]");
I am trying to iterate through a JSON array which has been encoded to a string for the purpose of storing on a queue. However, I receive the following error message:
{"code":"ExpressionEvaluationFailed","message":"The execution of
template action 'For_each' failed: The result '[{\"Foo\":\"Bar\"}]' of
the evaluation of 'foreach' action expression
'#{json(decodeBase64(triggerBody()['ContentData']))}' is not a valid
array."}
The following is the string being parsed:
[{"Foo":"Bar"}]
I have no problems parsing a JSON string when it is not in an array, for example:
{"Foo":"Bar"}
This parses just fine when I am not using a For_each.
How do I get the logic app to read this as an array?
The issue here is that you are using string interpolation (where expressions are wrapped in #{ ... }) that evaluates to a string representation of the array. Hence evaluation of the 'foreach' expression fails.
You want the expression to be
#json(decodeBase64(triggerBody()['ContentData']))
json(decodeBase64(body('HTTP')?['$Content']))
enter image description here
I use YamlDotnet to parse a yaml stream to a dictionary of string object via the YamlStream.
The YamlMappingType, YamlSequenceNode and YamlScalarNode are used in order to convert the value to a dictionary, a list or a string.
But I need to get a real boolean value instead of the string equivalent, and for that I use
bool.TryParse(value.ToString(), out valueBool)
value veing a YamlNode.
Is there a better way to do that?
Perhaps another child type of YamlNode?
EDIT:
I don't know the content of the YAML file, I just want to get a dictionary with his values.
Instead of doing the parsing manually, you should use the Deserializer class, which will convert a YAML document into an object graph.
var deserializer = new Deserializer();
var parsed = deserializer.Deserialize<...>(input);
You can see a working example here
I know how strings are compared and I read online that using:
assertEquals(String,String);
is safe... However I get following error:
junit.framework.AssertionFailedError: expected:<53> but was:<53>
In particular I do something like this:
assertEquals(totalRecipients.toString(), dataLineCount);
dataLineCount doesn't sound like a String to me - but I can't say for sure without looking at your code.
Assuming dataLineCount is an int you would not be calling assertEquals(String,String) but assertEquals(Object,Object) with a String and an Integer as arguments (because of autowrapping). And String and Integer don't compare equal...