Guest User

Untitled

a guest
Nov 16th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. string jsonBody='{"payload":[{"YearlylCostPercentage":"4.6","TotalRepayment":"120000","PropertyMarketValue":"100000","productname":"ABN Standard+","PaymentFrequency":"Monthly","NumberOfTerms":"60","NotaryName":"Notary","NotaryEmail":"raju.sen@yahoo.com","NotaryContactNumber":"0649991729","NotaryAdressLine2":"2563 CM The Hague","NotaryAdressLine1":"Valkenboslaan 72-F","nominalInterestRate":"4.5","MonthlyPayment":"600","MonthlyInterestAmount":"300","loanUtilizationDate":"12-1-2019","loanPurpose":"Loan","loanMaturityDate":"12-2-2019","LoanDuration":"5","loanAmount":"100000","KadasterLocation":"Amsterdam","InterestFixationProvision":"1.0","HandlingCost":"900","FixedInterestyear":"2.0","firstPaymentDate":"12-2-2019","FirstMonthlyPayment":"700","effectiveInterestRate":"4.7","DepartmentName":"Dev","CustomerDetails":[{"CustomerSalutation":"Geen titulatuur gewenst","CustomerName":"Eqaavq","AddressLine2":"1221 NH MDFMGDAKSV","AddressLine1":"Wdr Veuniztapbmr 345"},{ "CustomerSalutation":"Mevrouw","CustomerName":"Eqaavq-col Fpcysfptp","AddressLine2":"1221 NH MDFMGDAKSV","AddressLine1":"Wdr Veuniztapbmr 345"}],"city":"Amsterdam","BorrowedRatio":"1.4","AdvisorName":"Raju Sen","AdvisorContact":"0649991729","AdviseCost":"1000"}]}';
  2. Map<String, Object> jsonParseSource = (Map<String, Object>)JSON.deserializeUntyped(jsonBody);
  3. system.debug('Sai tets '+jsonParseSource);
  4. List<Map<String, String>> payload = new List<Map<String, String>>();
  5. List<Object> payLoadList=(List<Object>) jsonParseSource.get('payload');
  6. Object PayloadObj;
  7. if(payLoadList.size()>0)
  8. {
  9. PayloadObj=payLoadList[0];
  10. }
  11. String customerDetailString='';
  12. Map<String, Object> payloadBody = (Map<String, Object>)PayloadObj;
  13. system.debug('Sai tets '+payloadBody);
  14. for(String key: payloadBody.keyset()) {
  15. system.debug('Key '+key+ ' Value '+payloadBody.get(key));
  16. if(key == 'CustomerDetails')
  17. {
  18. List<Map<String,String>> tempMap= new List<Map<String,String>>();
  19. List<Object> tempList=(List<Object>)payloadBody.get(key);
  20. for(Object obj : tempList)
  21. {
  22. Map<String, Object> tempObj = (Map<String, Object>)obj;
  23. for(String tempKey: tempObj.keyset())
  24. {
  25. tempMap.add(new Map<String, String> { 'name' => tempKey, 'value' => (String)tempObj.get(tempKey) });
  26. system.debug('List Key '+tempKey+ ' List Value '+tempObj.get(tempKey));
  27. }
  28. }
  29. system.debug('tempMap'+tempMap);
  30. customerDetailString=JSON.serialize(new Map<String, List<Map<String, String>>> {
  31. key => tempMap
  32. });
  33. system.debug('customerDetailString'+customerDetailString);
  34. }
  35. else
  36. {
  37. payload.add(new Map<String, String> { 'name' => key, 'value' => (String)payloadBody.get(key) });
  38. }
  39. }
  40. String jsonResult = JSON.serialize(new Map<String, List<Map<String, String>>> {
  41. 'payload' => payload
  42. });
  43. String custpomerObjTemp=customerDetailString.substringAfter(':');
  44. system.debug(custpomerObjTemp);
  45. custpomerObjTemp=custpomerObjTemp.Left(custpomerObjTemp.Length() - 1);
  46. system.debug('Reult '+ custpomerObjTemp);
  47. String finalResult=jsonResult.Left(jsonResult.Length() - 2);
  48. finalResult=finalResult+',{"value":'+custpomerObjTemp+',"name":"CustomerDetails"}]}';
  49. system.debug(finalResult);
Add Comment
Please, Sign In to add comment