11-01-2017 02:10 AM - edited 03-14-2019 05:40 PM
Hi everyone
I have problem in planet GET JSON DOCUMENT DATA.
My json data return via respose is format JSON Array.
How to get element 2nd in result for picture below?
Please help me.
Solved! Go to Solution.
11-01-2017 02:07 PM - edited 11-01-2017 02:07 PM
I saw this and decided to poke around for a few minutes ;)
My guess is the "[{}]" is "unparsed" so
Use a DO Step
{ // Convert the "Unparsed" Data to an actual JSON Array net.minidev.json.JSONArray jArr = (net.minidev.json.JSONArray) net.minidev.json.JSONValue.parse(data); // Get the 2nd Item in the ArrayList as JSONArray inherits from List net.minidev.json.JSONObject jObj = (net.minidev.json.JSONObject) jArr.get(1); // You can use the JSON Doc now if you like..but if you just want to extract values into VARs just do it here int aId = jObj.get("areaId"); String aName = jObj.get("areaName"); String sDesc = jObj.get("description"); }
This is not the best way to deal with Arrays..but this gets to the data you asked for..
net.minidev.json is a Library that comes loaded with UCCX..not sure if this is a recommended Library to actually use..but you don't need any JARs for additional class paths.
11-01-2017 02:07 PM - edited 11-01-2017 02:07 PM
I saw this and decided to poke around for a few minutes ;)
My guess is the "[{}]" is "unparsed" so
Use a DO Step
{ // Convert the "Unparsed" Data to an actual JSON Array net.minidev.json.JSONArray jArr = (net.minidev.json.JSONArray) net.minidev.json.JSONValue.parse(data); // Get the 2nd Item in the ArrayList as JSONArray inherits from List net.minidev.json.JSONObject jObj = (net.minidev.json.JSONObject) jArr.get(1); // You can use the JSON Doc now if you like..but if you just want to extract values into VARs just do it here int aId = jObj.get("areaId"); String aName = jObj.get("areaName"); String sDesc = jObj.get("description"); }
This is not the best way to deal with Arrays..but this gets to the data you asked for..
net.minidev.json is a Library that comes loaded with UCCX..not sure if this is a recommended Library to actually use..but you don't need any JARs for additional class paths.
11-02-2017 12:15 AM
09-13-2018 11:37 AM
Hello Samuel,
I am anticipating getting a data that contains the following string, how do i go about getting a JSON Document and Getting JSON Data to be able to filter the output tranNr=0000414128123
"ResponseCode=11&tranNr=0000414128123&PostDate=2017-10-14T11:33:53.000&Amount=000000001000&Auth=Lem10&SiteCode=&CWEResponse=&CABBResultCode="
09-13-2018 01:32 PM
If you are receiving a Response String such as that..converting that to JSON would be unnecessary unless you need to pass it along to someone else in that format...
Otherwise, just parse that string using RegEx
String qs = "ResponseCode=....."; String re = "tranNr=(\d+)"; java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(re); java.util.regex.Matcher matcher = pattern.matcher(StringToSearch); if(matcher.find()) { String tranNrNum = matcher.group(1); }
09-13-2018 06:53 PM
To be honest, I’m not sure how to plug this into the script.
Thus far I have my create Document URL and I know when I run my HTTP Post request, the request post but I am not sure how to receive the data back from the HTTP post response. I have tried CreateXML Document/Get XML Document Data but I get some errors almost like it’s not able to parse the Data. Since the data is not in XML, I understand why I may not be able to retrieve the data.
if I try Create JSON Document/Get JSON Document Data, it’s almost as if I am not for mating the Create JSON Document properly hence I’m unable to attempt to pull any information either.
09-13-2018 10:35 PM
Ok..let's forget about Documents right now..1 Step @ a Time because it sounds to me like you are firing in the Dark with a blindfold on..Can you Provide for me..Paste or what not..the RAW Data you are Receiving Back from the POST Request...
09-15-2018 08:01 PM
Here is an example of the script I am working with. I am struggling with the Create JSON Document and Get JSON Document Data piece of the script.
If you send me your email, i will send you the actual script I am trying to get that specific response from.
As of now, I am not able to get any response back at all. If I use the create XML document and get XML document, I am getting an error. But the request is making it and being processed completely at the other end. I figured since the API is not in XML and its in more of a JSON format, it would be better to use the Create JSON Document and Get JSON Document Data steps but I am not familiar with using JSON.
09-15-2018 08:52 PM
Here is the actual script. If you run the data in the body on postman, you will see the response.. Essentially, I am unable to get the response to receive the response on the script and unsure of the way to pull it in. Even though I am evidently able to send the request and I see the request post on the URL.
09-17-2018 05:30 AM
09-20-2018 08:32 AM
03-20-2019 01:59 AM
Hello,
I tried to use the below code but i faced the attached error. Please advise.
{ // Convert the "Unparsed" Data to an actual JSON Array net.minidev.json.JSONArray jArr = (net.minidev.json.JSONArray) net.minidev.json.JSONValue.parse(data); // Get the 2nd Item in the ArrayList as JSONArray inherits from List net.minidev.json.JSONObject jObj = (net.minidev.json.JSONObject) jArr.get(1); // You can use the JSON Doc now if you like..but if you just want to extract values into VARs just do it here int aId = jObj.get("areaId"); String aName = jObj.get("areaName"); String sDesc = jObj.get("description"); }
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide