1. CJ Lai
  2. PowerBuilder
  3. Thursday, 30 June 2022 15:49 PM UTC

Hi 

I need your help or advice.

Below is a sample JSON that is returned from a HttpClient GET call. (It'll be easier to view if you copy/paste to a JSON editor.)

{
"loanType": "NewLead",
"loan": {
"id": 7,
"loanType": "NewLead",
"ucid": 1,
"branchId": "1281",
"loanStatus": "Funded",
"amountPaidToCustomer": 44,
"jointType": "COSIGN"
}
},
{
"loanType": "FormerBorrower",
"loan": {
"id": 8,
"loanType": "FormerBorrower",
"ucid": 1,
"branchId": "1281",
"loanStatus": "Viewed",
"amountPaidToCustomer": 33,
"jointType": "INDVDUAL"
}
},
{
"loanType": "Renewal",
"loan": {
"loanId": 1,
"previousLoanPayOffAmount": 1285.5,
"previousAccountID": 1234,
"accountOption": null,
"id": 0,
"loanType": "Renewal",
"ucid": 1,
"branchId": "1281",
"loanStatus": "Pending",
"amountPaidToCustomer": 1250,
"jointType": "JOINT"
}
}

 

How do I load those data fields into a dwo only when the LoanType = 'Renewal'?

I have looked those answers and examples online but the JsonParser.GetITemArray always returned -1...

Appreciate your help!

Accepted Answer
Ken Guo @Appeon Accepted Answer Pending Moderation
  1. Friday, 1 July 2022 01:16 AM UTC
  2. PowerBuilder
  3. # Permalink

Hi,

 You can try getting json data with the following code when LoanType = 'Renewal':

String  ls_ret
long ll_RootObject,ll_articles_array,ll_row_item,ll_loan_item
long ll_childcount,i
JsonParser  lnv_JsonParser 
lnv_JsonParser = create JsonParser 

String ls_json
ls_json = &
'[{'+&
'"loanType": "NewLead",'+&
'"loan": {'+&
'"id": 7,'+&
'"loanType": "NewLead",'+&
'"ucid": 1,'+&
'"branchId": "1281",'+&
'"loanStatus": "Funded",'+&
'"amountPaidToCustomer": 44,'+&
'"jointType": "COSIGN"'+&
'}'+&
'},'+&
'{'+&
'"loanType": "FormerBorrower",'+&
'"loan": {'+&
'"id": 8,'+&
'"loanType": "FormerBorrower",'+&
'"ucid": 1,'+&
'"branchId": "1281",'+&
'"loanStatus": "Viewed",'+&
'"amountPaidToCustomer": 33,'+&
'"jointType": "INDVDUAL"'+&
'}'+&
'},'+&
'{'+&
'"loanType": "Renewal",'+&
'"loan": {'+&
'"loanId": 1,'+&
'"previousLoanPayOffAmount": 1285.5,'+&
'"previousAccountID": 1234,'+&
'"accountOption": null,'+&
'"id": 0,'+&
'"loanType": "Renewal",'+&
'"ucid": 1,'+&
'"branchId": "1281",'+&
'"loanStatus": "Pending",'+&
'"amountPaidToCustomer": 1250,'+&
'"jointType": "JOINT"'+&
'}'+&
'}]'

ls_ret = lnv_JsonParser.LoadString(ls_json)   
If ls_ret <> '' Then
	Messagebox('Load file Failed.',ls_ret)
	Return 
End If 

ll_RootObject = lnv_JsonParser.GetRootItem()
ll_childcount =  lnv_JsonParser.GetChildCount(ll_RootObject)

Long ll_id, ll_ucid,ll_amountPaidToCustomer, ll_previousAccountID
String ls_jointType, ls_loantype, ls_loanStatus,ls_branchId,ls_accountOption
Dec ls_previousLoanPayOffAmount
For i = 1 to ll_childcount
	ll_row_item = lnv_JsonParser.GetChildItem(ll_RootObject, i)
		ls_loanType = lnv_JsonParser.GetItemString(ll_row_item,'loanType')
		If ls_loanType = 'Renewal' Then
			ll_loan_item = lnv_JsonParser.GetItemObject(ll_row_item, "loan")
			//ls_previousLoanPayOffAmount =  lnv_JsonParser.GetItemDecimal(ll_loan_item,'previousLoanPayOffAmount') //Only PB 2022 support GetItemDecimal function
			ll_previousAccountID = lnv_JsonParser.GetItemNumber(ll_loan_item,'previousAccountID')
			If lnv_JsonParser.GetItemType(ll_loan_item,'accountOption') = JsonNullItem! Then
				ls_accountOption = 'Null'
			End If
			ll_id = lnv_JsonParser.GetItemNumber(ll_loan_item,'id')
			ls_loantype = lnv_JsonParser.GetItemString(ll_loan_item,'loanType')
			ll_ucid = lnv_JsonParser.GetItemNumber(ll_loan_item,'ucid')
			ls_branchId = lnv_JsonParser.GetItemString(ll_loan_item,'branchId')
			ls_loanStatus = lnv_JsonParser.GetItemString(ll_loan_item,'loanStatus')
			ll_amountPaidToCustomer = lnv_JsonParser.GetItemNumber(ll_loan_item,'amountPaidToCustomer')
			ls_jointType = lnv_JsonParser.GetItemString(ll_loan_item,'jointType')
		End If
Next
Comment
There are no comments made yet.
Daryl Foster Accepted Answer Pending Moderation
  1. Friday, 1 July 2022 00:50 AM UTC
  2. PowerBuilder
  3. # 1

Have you got some example code of what you have tried already?  I don't think the json that you have posted is valid unless it is wrapped in [ ] to make it an array. The json you've posted doesn't have any arrays in it, so it would be helpful to see how you've used GetItemArray in your code.

Comment
  1. CJ Lai
  2. Tuesday, 5 July 2022 16:01 PM UTC
Hi Daryl

You are correct. There are no arrays in the JSON. I was mistaken and thought the data elements under 'loan' were in an array.

Thank you for your comment!

CJ
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.