cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
5116
Views
0
Helpful
11
Replies

How to get specified jsonOject in planet GET JSON DOCUMENT DATA in uccx 11.6

ChienNX
Level 1
Level 1

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.

1 Accepted Solution

Accepted Solutions

Samuel Womack
Level 5
Level 5

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.

View solution in original post

11 Replies 11

Samuel Womack
Level 5
Level 5

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.

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="

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);
}

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. 

 

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...

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.

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.

Your "Actual Script" doesn't do anything.

I just realized i attached the wrong one. In the one i sent before,  I looked into the Script and the ‘Create URL Document' was a bit messed up.

 

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");
}