Link to home
Create AccountLog in
Avatar of Connie McBride
Connie McBride

asked on

Delphi XE, DataSnap, JSon and java

issue:
I am developing web services in delphi xe, using datasnap.
I have code that is opening a query and returning it.
using chrome, the return of a query looks like this:
[TdbSMEPortal.GetTechOpenTasks
Result:	{"TechUID":"UR022610153524916299","result":{"table":[["RecUID",18,0,0,0,8,0,0,false,false,0,false,false],["UID",1,1,0,20,21,0,0,false,false,0,false,false],["OrderUID",1,2,0,20,21,0,0,false,false,0,false,false],["CustUID",1,3,0,20,21,0,0,false,false,0,false,false],,

"RecUID":[1749,1751,2733,2788,2800,2872,2874],"UID":["ot020111131519715183","ot020111131735615165","ot071911161863660554","ot080311134850911479","ot080411111061929916","ot081511131473467171","ot081511131655902124"],"OrderUID":["CL201101191013960738","CL201101261713425781","IO071411120091634644","CL201108020905697283","CL201107221145847628","CL201107131019828426","CL201108021030658338"],"

Open in new window


My co-worker, who is doing the java script side, says this is not standard json format, and she can't work with it. (she is looking for name value pairs, and says this is not it)
I know little and nothing about json.
if this is the case, how do I make it return in standard json format?  If this is not the case, where do I point her to to help her work with this format?
does XE3 generate 'standard' json format?
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Did you try this json components?
http://sourceforge.net/projects/lkjson/
http://code.google.com/p/superobject/
http://code.google.com/p/dwscript/

Some source whichs can help you too:
http://edn.embarcadero.com/article/40882
http://docwiki.embarcadero.com/RADStudio/XE3/en/JSON

Generaly, using one of this components (writer) can generate json compatible request.
Avatar of rinfo
rinfo

Maybe you need to add   ?json=true   as a parameter to your query url.
http://host:port/datasnap/rest/[Class]/[Method]/?json=true
Avatar of Connie McBride

ASKER

So, (starting with simplest case), I added /?json=true to url
and got this result:
{"result":[{"table":[["RecUID",18,0,0,0,8,0,0,false,false,0,false,false],["UID",1,1,0,20,21,0,0,false,false,0,false,false],["OrderUID",1,2,0,20,21,0,0,false,false,0,false,false],["CustUID",1,3,0,20,21,0,0,false,false,0,false,false],["CustName",1,4,0,80,81,0,0,false,false,0,false,false],["WorkGroupUID",1,5,0,20,21,0,0,false,false,0,false,false],["WorkGroup",1,6,0,40,41,0,0,false,false,0,false,false],["TechUID",1,7,0,20,21,0,0,false,false,0,false,false],["Tech",1,8,0,40,41,0,0,false,false,0,false,false],["DateIn",11,9,0,0,8,0,0,false,false,0,false,false],["OrderNumber",18,10,0,0,8,0,0,false,false,0,false,false],["ScheduledHours",7,11,0,0,8,15,0,false,false,0,false,false],["BillHours",7,12,0,0,8,15,0,false,false,0,false,false],["LaborRate",7,13,0,0,8,0,0,false,false,0,false,false],["LaborCost",7,14,0,0,8,0,0,false,false,0,false,false],["PriceBookUID",1,15,0,20,21,0,0,false,false,0,false,false],["PriceBook",1,16,0,40,41,0,0,false,false,0,false,false],["PayWageUID",1,17,0,20,21,0,0,false,false,0,false,false],["PayWage",1,18,0,40,41,0,0,false,false,0,false,false],["ServiceItemUID",1,19,0,20,21,0,0,false,false,0,false,false],["ServiceItem",1,20,0,40,41,0,0,false,false,0,false,false],["TimeStart",11,21,0,0,8,0,0,false,false,0,false,false],["TimeEnd",11,22,0,0,8,0,0,false,false,0,false,false],["PrePaidHours",7,23,0,0,8,15,0,false,false,0,false,false],["TotalCost",7,24,0,0,8,0,0,false,false,0,false,false],["TotalCharge",7,25,0,0,8,0,0,false,false,0,false,false],["ItemProfit",7,26,0,0,8,0,0,false,false,0,false,false],["TotalProfit",7,27,0,0,8,0,0,false,false,0,false,false],["QBModified",11,28,0,0,8,0,0,false,false,0,false,false],["NonTaxable",4,29,0,0,2,0,0,false,false,0,false,false],["ClassUID",1,30,0,20,21,0,0,false,false,0,false,false],["Class",1,31,0,40,41,0,0,false,false,0,false,false],["StartDateTime",11,32,0,0,8,0,0,false,false,0,false,false],["EndDateTime",11,33,0,0,8,0,0,false,false,0,false,false],["IsLocked",4,34,0,0,2,0,0,false,false,0,false,false],["OrderDetailUID",1,35,0,20,21,0,0,false,false,0,false,false],["SLACatUID",1,36,0,20,21,0,0,false,false,0,false,false],["SLACategory",1,37,0,40,41,0,0,false,false,0,false,false],["IsFixed",4,38,0,0,2,0,0,false,false,0,false,false],["QBLabor",1,39,0,36,37,0,0,false,false,0,false,false],["TaxCodeUID",1,40,0,20,21,0,0,false,false,0,false,false],["TaxCode",1,41,0,45,46,0,0,false,false,0,false,false],["IsDownloadedbyTechnician",4,42,0,0,2,0,0,false,false,0,false,false],["OrderAccepted",4,43,0,0,2,0,0,false,false,0,false,false],["DateDownloaded",11,44,0,0,8,0,0,false,false,0,false,false],["Note",1,45,0,200,201,0,0,false,false,0,false,false],["SetBilling",4,46,0,0,2,0,0,false,false,0,false,false],["CustEQUID",1,47,0,20,21,0,0,false,false,0,false,false],["CustEQItem",1,48,0,40,41,0,0,false,false,0,false,false],["SerialNumber",1,49,0,45,46,0,0,false,false,0,false,false],["UseCustomRates",4,50,0,0,2,0,0,false,false,0,false,false],["TaskStatusUID",1,51,0,20,21,0,0,false,false,0,false,false],["TaskStatus",1,52,0,40,41,0,0,false,false,0,false,false],["IsSub",4,53,0,0,2,0,0,false,false,0,false,false],["Unavailable",4,54,0,0,2,0,0,false,false,0,false,false],["QBExport",4,55,0,0,2,0,0,false,false,0,false,false],["qbBillExport",4,56,0,0,2,0,0,false,false,0,false,false],["POID",1,57,0,36,37,0,0,false,false,0,false,false],["BillID",1,58,0,36,37,0,0,false,false,0,false,false],["MatUID",1,59,0,20,21,0,0,false,false,0,false,false],["SalesCommissionRate",7,60,0,0,8,7,0,false,false,0,false,false],["SalesCommission",7,61,0,0,8,0,0,false,false,0,false,false],["TechCommissionRate",7,62,0,0,8,7,0,false,false,0,false,false],["Techcommission",7,63,0,0,8,0,0,false,false,0,false,false],["TotalSalesCommission",7,64,0,0,8,0,0,false,false,0,false,false],["TotalTechCommission",7,65,0,0,8,0,0,false,false,0,false,false],["TechCostBased",4,66,0,0,2,0,0,false,false,0,false,false],["SalesCostBased",4,67,0,0,2,0,0,false,false,0,false,false],["Publish",4,68,0,0,2,0,0,false,false,0,false,false],["rptDays",6,69,0,0,4,0,0,false,false,0,false,false],["ModByDispatch",4,70,0,0,2,0,0,false,false,0,false,false],["DispatchHPD",7,71,0,0,8,15,0,false,false,0,false,false],["DispatchHours",7,72,0,0,8,15,0,false,false,0,false,false],["DispatchEndDate",11,73,0,0,8,0,0,false,false,0,false,false],["ItemDiscountRate",7,74,0,0,8,7,0,false,false,0,false,false],["ItemDiscount",7,75,0,0,8,0,0,false,false,0,false,false],["TotalDiscount",7,76,0,0,8,0,0,false,false,0,false,false],["PartnerDiscountRate",7,77,0,0,8,7,0,false,false,0,false,false],["PartnerDiscount",7,78,0,0,8,0,0,false,false,0,false,false],["TotalPartnerDiscount",7,79,0,0,8,0,0,false,false,0,false,false],["WhoEdit",1,80,0,40,41,0,0,false,false,0,false,false],["EditDateTime",11,81,0,0,8,0,0,false,false,0,false,false],["EditCount",6,82,0,0,4,0,0,false,false,0,false,false],["EditModule",1,83,0,30,31,0,0,false,false,0,false,false],["LocationID",1,84,0,10,11,0,0,false,false,0,false,false],["EditUID",1,85,0,20,21,0,0,false,false,0,false,false],["dParentRecUID",18,86,0,0,8,0,0,false,false,0,false,false],["dParentUID",1,87,0,20,21,0,0,false,false,0,false,false]],"RecUID":[1750,1752,2264,2739,2773,2778,2782,2836,2877,2883,2885],"UID":["ot020111131510712654","ot020111131762236427","ot041711104288799857","ot071911162081920522","ot072711161455123156","ot080311133860552998","ot080311134357214373","ot081111105464965044","ot081511131928125876","ot081611120071683148","ot081611120266301526"],"OrderUID":["CL201101191013960738","CL201101261713425781","CL201104151238906840","IO071411120091634644","IO072611141842077312","CL201107221203113009","CL201107221157940519","IO080511090441052867","IO080511090441052867","IO071511115342577294","CL201107221140822726"],"CustUID":["CM022610154310062679","CM022610154354798679","CM022610154350524724","CM022610154326676199","CM122310154142718036","CM022610154477292553","CM071911180417935293","CM022610154295558961","CM022610154295558961","CM022610154359115446","CM022610154359115446"],"CustName":["Jefferson Parish Public Schools","Jefferson Parish Technology","Fisher Middle-High","Claiborne Elem","Melrose Lower Elementary","Lutcher High School","Lutcher Elementary","Melrose Elementary (AXI)","Melrose Elementary (AXI)","Woodvale Elementary","Woodvale Elementary"],"WorkGroupUID":["","","","","","","","","","",""],"WorkGroup":["","","","","","","","","","",""],"TechUID":["UR022610153651973352","UR022610153651973352","UR022610153651973352","UR022610153651973352","UR022610153651973352","UR022610153651973352","UR022610153651973352","UR022610153651973352","UR022610153651973352","UR022610153651973352","UR022610153651973352"],"Tech":["Tony Tran","Tony Tran","Tony Tran","Tony Tran","Tony Tran","Tony Tran","Tony Tran","Tony Tran","Tony Tran","Tony Tran","Tony Tran"],"DateIn":["2011-01-27.0","2011-01-27.0","2011-04-18.0","2011-07-20.0","2011-07-15.0","2011-08-04.0","2011-08-04.0","2011-08-06.0","2011-08-16.0","2011-08-17.0","2011-08-17.0"],"OrderNumber":[4408,4454,5061,5420,5468,5457,5455,5513,5513,5426,5450],"ScheduledHours":[3,3,3,8,8,8,3,6,3,8,8],"BillHours":[0,0,0,0,0,0,0,0,0,0,0],"LaborRate":[0,0,0,0,0,0,0,0,0,0,0],"LaborCost":[0,0,0,0,0,0,0,0,0,0,0],"PriceBookUID":["","","","","","","","","","",""],"PriceBook":["","","","","","","","","","",""],"PayWageUID":["","","","","","","","","","",""],"PayWage":["","","","","","","","","","",""],"ServiceItemUID":["","","","","","","","","","",""],"ServiceItem":["","","","","","","","","","",""],"TimeStart":["1899-12-30 09:00:00.0","1899-12-30 09:00:00.0","1899-12-30 06:00:00.0","1899-12-30 06:30:00.0","1899-12-30 06:30:00.0","1899-12-30 06:30:00.0","1899-12-30 06:30:00.0","1899-12-30 07:00:00.0","1899-12-30 06:00:00.0","1899-12-30 09:00:00.0","1899-12-30 09:00:00.0"],"TimeEnd":["1899-12-30 12:00:00.0","1899-12-30 12:00:00.0","1899-12-30 09:00:00.0","1899-12-30 14:30:00.0","1899-12-30 14:30:00.0","1899-12-30 14:30:00.0","1899-12-30 09:30:00.0","1899-12-30 13:00:00.0","1899-12-30 09:00:00.0","1899-12-30 17:00:00.0","1899-12-30 17:00:00.0"],"PrePaidHours":[0,0,0,0,0,0,0,0,0,0,0],"TotalCost":[0,0,0,0,0,0,0,0,0,0,0],"TotalCharge":[0,0,0,0,0,0,0,0,0,0,0],"ItemProfit":[0,0,0,0,0,0,0,0,0,0,0],"TotalProfit":[0,0,0,0,0,0,0,0,0,0,0],"QBModified":[null,null,null,null,null,null,null,null,null,null,null],"NonTaxable":[true,true,true,true,true,true,true,true,true,true,true],"ClassUID":["","","","","","","","","","",""],"Class":["","","","","","","","","","",""],"StartDateTime":["2011-01-27 09:00:00.0","2011-01-27 09:00:00.0","2011-04-18 06:00:00.0","2011-07-20 06:30:00.0","2011-07-15 06:30:00.0","2011-08-04 06:30:00.0","2011-08-04 06:30:00.0","2011-08-06 07:00:00.0","2011-08-16 06:00:00.0","2011-08-17 09:00:00.0","2011-08-17 09:00:00.0"],"EndDateTime":["2011-01-27 12:00:00.0","2011-01-27 12:00:00.0","2011-04-18 09:00:00.0","2011-07-20 14:30:00.0","2011-07-15 14:30:00.0","2011-08-04 14:30:00.0","2011-08-04 09:30:00.0","2011-08-06 13:00:00.0","2011-08-16 09:00:00.0","2011-08-17 17:00:00.0","2011-08-17 17:00:00.0"],"IsLocked":[false,false,false,false,false,false,false,false,false,false,false],"OrderDetailUID":["OD201102011315749199","OD201102011317575490","OD201104171042676667","OD201107191620837327","OD201107271615625165","OD201108031338130531","OD201108031343131413","OD201108111054599210","OD201108151319716918","OD201108161201769205","OD201108161202336952"],"SLACatUID":["","","","","","","","","","",""],"SLACategory":["","","","","","","","","","",""],"IsFixed":[false,false,false,false,false,false,false,false,false,false,false],"QBLabor":["","","","","","","","","","",""],"TaxCodeUID":["","","","","","","","","","",""],"TaxCode":["","","","","","","","","","",""],"IsDownloadedbyTechnician":[false,false,false,false,false,false,false,false,false,false,false],"OrderAccepted":[false,false,false,false,false,false,false,false,false,false,false],"DateDownloaded":[null,null,null,null,null,null,null,null,null,null,null],"Note":["","","","","","","","","","",""],"SetBilling":[false,false,false,false,false,false,false,false,false,false,false],"CustEQUID":["","","","","","","","","","",""],"CustEQItem":["","","","","","","","","","",""],"SerialNumber":["","","","","","","","","","",""],"UseCustomRates":[false,false,false,false,false,false,false,false,false,false,false],"TaskStatusUID":["OF030510143618000455","OF030510143618000455","OF030510143618000455","OF030510143618000455","OF030510143618000455","OF030510143618000455","OF030510143618000455","OF030510143618000455","OF030510143618000455","OF030510143618000455","OF030510143618000455"],"TaskStatus":["Installation Scheduled","Installation Scheduled","Installation Scheduled","Installation Scheduled","Installation Scheduled","Installation Scheduled","Installation Scheduled","Installation Scheduled","Installation Scheduled","Installation Scheduled","Installation Scheduled"],"IsSub":[false,false,false,false,false,false,false,false,false,false,false],"Unavailable":[false,false,false,false,false,false,false,false,false,false,false],"QBExport":[false,false,false,false,false,false,false,false,false,false,false],"qbBillExport":[false,false,false,false,false,false,false,false,false,false,false],"POID":["","","","","","","","","","",""],"BillID":["","","","","","","","","","",""],"MatUID":["","","","","","","","","","",""],"SalesCommissionRate":[0,0,0,0,0,0,0,0,0,0,0],"SalesCommission":[0,0,0,0,0,0,0,0,0,0,0],"TechCommissionRate":[0,0,0,0,0,0,0,0,0,0,0],"Techcommission":[0,0,0,0,0,0,0,0,0,0,0],"TotalSalesCommission":[0,0,0,0,0,0,0,0,0,0,0],"TotalTechCommission":[0,0,0,0,0,0,0,0,0,0,0],"TechCostBased":[false,false,false,false,false,false,false,false,false,false,false],"SalesCostBased":[false,false,false,false,false,false,false,false,false,false,false],"Publish":[false,false,false,false,false,false,false,false,false,false,false],"rptDays":[1,1,1,1,1,1,1,1,1,1,1],"ModByDispatch":[false,false,false,false,false,false,false,false,false,false,false],"DispatchHPD":[3,3,3,3,3,3,3,3,3,3,3],"DispatchHours":[3,3,3,8,8,8,3,6,3,8,8],"DispatchEndDate":["2011-01-27 12:00:00.0","2011-01-27 12:00:00.0","2011-04-18.0","2011-07-20.0","2011-07-15.0","2011-08-04.0","2011-08-04.0","2011-08-06.0","2011-08-16.0","2011-08-17.0","2011-08-17.0"],"ItemDiscountRate":[0,0,0,0,0,0,0,0,0,0,0],"ItemDiscount":[0,0,0,0,0,0,0,0,0,0,0],"TotalDiscount":[0,0,0,0,0,0,0,0,0,0,0],"PartnerDiscountRate":[0,0,0,0,0,0,0,0,0,0,0],"PartnerDiscount":[0,0,0,0,0,0,0,0,0,0,0],"TotalPartnerDiscount":[0,0,0,0,0,0,0,0,0,0,0],"WhoEdit":["Karen","Karen","Karen","Karen","Karen","Karen","Karen","Karen","Karen","Karen","Karen"],"EditDateTime":["2011-02-01 13:15:49.753","2011-02-01 13:17:29.270","2011-04-17 10:42:26.197","2011-07-19 16:20:15.470","2011-07-27 16:15:05.770","2011-08-03 13:38:42.270","2011-08-03 13:43:14.677","2011-08-11 10:54:23.713","2011-08-15 13:19:48.327","2011-08-16 12:01:04.683","2011-08-16 12:02:27.567"],"EditCount":[1,1,1,1,1,1,1,1,1,1,1],"EditModule":["Install Orders 7.1.7.68","Install Orders 7.1.7.68","Install Orders 7.1.12.102","Install Orders 7.1.19.151","Dispatch 7.1.19.151","Install Orders 7.1.19.151","Dispatch 7.1.19.151","Install Orders 7.1.19.151","Install Orders 7.1.19.151","Install Orders 7.1.19.151","Install Orders 7.1.19.151"],"LocationID":["","","","","","","","","","",""],"EditUID":["UR022610153584672972","UR022610153584672972","UR022610153584672972","UR022610153584672972","UR022610153584672972","UR022610153584672972","UR022610153584672972","UR022610153584672972","UR022610153584672972","UR022610153584672972","UR022610153584672972"],"dParentRecUID":[0,0,0,0,0,0,0,0,0,0,0],"dParentUID":["","","","","","","","","","",""]}]}

Open in new window


I stuck it into a couple of online json viewers, and got the results of name=[array of values]
the front end developer is telling me that jquery cannot parse it, therefore it cannot be used.
seems to me that this is a more efficient method of coding it, vs name=value, name = value, name = value, etc, but okay.

can anyone point me to an example of code that will parse this out for the developer?

meanwhile, back at the ranch, I am looking into the suggested components to see how to implement on a dataset.
thank you
ASKER CERTIFIED SOLUTION
Avatar of rinfo
rinfo

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
or you can tell them to use following function
$.ajax({
        url: "yoururlquery",
        headers: {"Accept": "application/json",
                  "Content-Type": "text/plain;charset=UTF-8"
                 },
        success: function(data) {
          alert(data);
        }
       });
progress:
jQuery.parseJSON(itemJson) is the function she always uses and she is getting 'undefined response'.

so I added logic that creates a JSONArry of JSONObjects which is created using addPair to get her the name value pairs.
similar to :
{"mineOnly":"false","result":[{"UID":"CM013111152777717249","FullName":"Coghill Accelerated School"},{"UID":"CM021011114612698337","FullName":"Orleans Parish Public Schools:Charles R. Drew Elementary"}]}

Open in new window


she says:
Ok, this format is working without the "{"mineOnly":"false","result":" and the last character "}". If i delete them it works. If not, it doesn't.

so, it is including the parameters and the result of the jsp call.
that part of it is generated from the delphi side of things, I think.
is there an easy way for her to be able to just pull out the result?