KMota
(karina)
July 8, 2020, 1:14pm
1
Hello everyone,
I’m having trouble accessing the values of a Json. I’ve tried several ways
Array
item (“name”). tostring
item.selettoken
Nothing works.
Can someone help me
JObject(2)
{
JProperty(1)
{
JArray(359)
{
JObject(9)
{
JProperty(1)
{
[null]
},
JProperty(1)
{
[00.01.001.001 - FM2C - CORPORATIVO - SP - MATRIZ]
},
JProperty(1)
{
[null]
},
JProperty(1)
{
[null]
},
JProperty(1)
{
[9600181]
},
JProperty(1)
{
[0001001001]
},
JProperty(1)
{
[00.01.001.001]
},
JProperty(1)
{
[null]
},
JProperty(1)
{
[vicente.sousa@fm2c.com.br]
}
},
JObject(9)
{
JProperty(1)
{
[null]
},
JProperty(1)
{
[00.01.001.111 - FM2C - DESP. TRANSITORIA - GESTAO - 01/2020]
},
JProperty(1)
{
[null]
},
JProperty(1)
{
[null]
},
-------------------------------------------------------- Json
{
"content": [
{
"EMAIL_COORDENADOR": "null",
"DESCRI": "00.01.001.001 - FM2C - CORPORATIVO - SP - MATRIZ",
"APROV_GERENTE": "null",
"EMAIL_GERENTE": "null",
"APROV_DIRETOR": "9600181",
"CCUSTO": "0001001001",
"UN": "00.01.001.001",
"APROV_COORDENADOR": "null",
"EMAIL_DIRETOR": "vicente.sousa@fm2c.com.br"
},
I need to access o CCUSTO
errors presented
Write Line: Cannot access child value on Newtonsoft.Json.Linq.JProperty.
and
and
Deserialize JSON Array: Error reading JArray from JsonReader. Path ‘’, line 0, position 0.
KMota:
{
"content": [
{
"EMAIL_COORDENADOR": "null",
"DESCRI": "00.01.001.001 - FM2C - CORPORATIVO - SP - MATRIZ",
"APROV_GERENTE": "null",
"EMAIL_GERENTE": "null",
"APROV_DIRETOR": "9600181",
"CCUSTO": "0001001001",
"UN": "00.01.001.001",
"APROV_COORDENADOR": "null",
"EMAIL_DIRETOR": "vicente.sousa@fm2c.com.br"
},
Is this the Whole Json Content?
Hi @KMota
try using both of this below ways
JsonObjVariable(“CCUSTO”).ToString outside foreach activity within messagebox or writeline activity
OR
JsonObjVariable(“content”)(“CCUSTO”).ToString outside foreach activity within messagebox or writeline activity
Where JsonObjVariable is the output variable you got from Deserialize JSON Activity
Mark as solution and like it if this help you
Happy Automation
Best Regards
Er Pratik Wavhal
3 Likes
KMota
(karina)
July 8, 2020, 1:58pm
5
Hi @Pratik_Wavhal
in the first case it presents all the Json, it works, but I only need the CCUSTO
in the second case it gave this error
resulte(“content”)(0)(“CCUSTO”).ToString
I put it like this, I think it was, I just need to set the index
@KMota Check this Workflow :
JsonValueExtraction.zip (2.5 KB)
2 Likes
@KMota You can also Access it in this way Without For Each.
4 Likes
KMota
(karina)
July 8, 2020, 2:14pm
10
Hi,
after running several CCUSTO he gave this error, can you tell me about something
@KMota Is the Value Present in it? It might be because the value is Empty or not present in the Json
KMota
(karina)
July 8, 2020, 2:18pm
12
could it be, in this case, that there are no more CCUSTO to seek?
In this case, as there is no more CCUSTO, how can I escape this error and continue the application
@KMota Depending on whether CCUSTO is present or not, you can use this method :
KMota
(karina)
July 8, 2020, 2:25pm
14
I understand, it may really happen that some case comes without the COST, but it gave this error
@KMota ContainsKey has a Wrong Spelling
KMota
(karina)
July 8, 2020, 2:37pm
17
that’s right, he is giving an error, because a call arrives that does not have the COST, but still presents the error
I tried like that too,
KMota
(karina)
July 8, 2020, 2:44pm
19
no, when it arrives at the index that returns null on the COST it gives the error of an unreferenced object.
then I tried it the other way, but it also didn’t work, I’ll try to put it in a try catch, but I still don’t know how to escape this error. In the API it really arrives in that call and returns NULL to the COST,
he would have to move on to the next
@KMota The ContainsKey method should have escaped the Error actually . I tested the same workflow, by editing the Json Value, By Removing the Key “CCUSTO” and making the value as Empty. It didn’t throw an error using that If Statement.