Hi,
I am working on http call (API) and getting below sample response.
{
“ObjectA”: {
“Name”: “Fruit”,
“Color”: “Red”
},
“contains”: [
{
“FruitName”: “Mango”,
“IsFound”: “Yes”
}
]
}
Now I have to check the Condition if IsFound is Yes, then I have to extract FruitName as Mango.
Any help is greatly appreciated.
Thanks in advance.
1 Like
TimK
(Tim Kok)
2
You need to de-serialize it first then get the element root for ‘contains’ from the xdoc
Xdoc.Root.Descendants(XNameSpace+ “contains”)
then access the IsFound element within that by de-serializing that into a new xdoc:
xdocContains.Root.Descendants(XNameSpace+ “IsFound”).value.tostring
Hi TimK,
Thanks, but how can I get XnsGCNS?
My requirement is to extract FruitName if IsFound equals to Yes.
Yoichi
(Yoichi)
4
Hi,
Can you try the following?
- First, Deserialize your string using Deserialize Json activity in Web Activity Package.
- Then you can get JObject variable (Let’s say
jo
).
- Next you can get JToken variable (say
jt
) like jt=jo("contains")
- Finally, you can get each value as
jt.First.Item("FruitName")
and jt.First.Item("FruitName")
Regards,
2 Likes
TimK
(Tim Kok)
5
Sorry XnsGCNS is just an argument name - Xns - is the XNamespace (This is probably isnt required.)
Take a look at this link
Hi Yoichi,
Thanks. It is very much useful.
If it has multiple nodes with different IsFound, then it is a problem. For example,
{
“ObjectA”: {
“Name”: “Fruit”,
“Color”: “Red”
},
“contains”: [
{
“FruitName”: “Mango”,
“IsFound”: “Yes”
},
{
“FruitName”: “Banana”,
“IsFound”: “No”
},
{
“FruitName”: “Apple”,
“IsFound”: “Yes”
},
{
“FruitName”: “Grapes”,
“IsFound”: “Yes”
}
]
}
In this case, I have to get Mango, Apple and Grapes
Thanks in advance.
Yoichi
(Yoichi)
7
Hi,
It would be like the following image.
sample20191203.xaml (6.3 KB)
2 Likes
HareeshMR
(Hareesh Madasi)
8
Check this @chandrasekhar.jella
jsondata.xaml (6.0 KB)
You can check for the name of the fruit to get the value and get the required value of flag
Hi Yoichi,
Thanks for sharing logic and it’s working.
1 Like
system
(system)
Closed
10
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.