停车场收费标准典型案例:
返回值:JSON格式的字符串
{
'服务id ' : ' 3c.park.queryparkstandard ',
' resultCode':0,
'消息' : '成功',
'数据项目' : [ {
' objectId': ',
'操作类型' : '读取',
' attributes':{
' parkCode': 'park01 ',
' parkName': 'KKMALL_PARK ',
' tempStandard': '临时牌价标准说明'
(,
' subItems': [
{
' objectId': ',
'操作类型' : '读取',
' attributes': {
' cardType': '月卡a '
(,
' subItems': [
{
' objectId': ',
'操作类型' : '读取',
' attributes': {
' monthPeriod':1,
' money':150
(,
' subItems': []
}
]
(,
{
' objectId': ',
'操作类型' : '读取',
' attributes': {
' cardType': '月卡b '
(,
' subItems': [
{
' objectId': ',
'操作类型' : '读取',
' attributes': {
' monthPeriod':1,
' money':100
(,
' subItems': []
}
]
}
]
() ) ]
}
获取dataItems内容和转换
stringjsonstring=queryparkstandardservices.execute (params,type );
jsonobjectjsonobject=newjsonobject (;
Jonobject.put(JSON0)、JSON字符串); 如果String是[{}, ]的形式,则可以创建新的单个json {json0:}
system.out.println (_ _ _ _ _ _ _ _ 0824---- JSON string );
JSON array JSON array=new JSON array (;
jonarray.add (JSON对象; 如果jsonobject的value为{json0:[{}, }}的形式,则由JSONArray承担
JSONobjectobresult=(JSONobject ) JSONarray.get(0;
jsonarrayjsonarray 01=ob result.getjsonarray (' JSON0);
JSONobjectJSON01=(JSONobject ) JSONarray01.get(0;
jsonobjectpartone=JSON 01.getjsonobject (' attributes );
字符串包代码=(字符串) partone.get (包代码); //停车场编号
String parkName=(String ) partone.get('parkname ); //停车场的名称
String tempStandard=(String ) partone.get('tempstandard ); //临时牌价说明
jonarrayparttwo=JSON 01.getjsonarray (subitems );
listfeestandardfeestandards=new ArrayList (;
for(intI=0; iparttwo.size (; I ) {
feestandardfeestandard=newfee standard (;
feestandard.setparkcode (park codes;
feestandard.setparkname (park name );
feestandard.settempstandard (临时标准;
jsonobjectobresult2=newjsonobject (;
obresult2=(JSONobject ) parttwo.get(i ) I;
jsonobjectAttributes=(JSON object ) obresult2.get ) (attributes );
String cardType0=(String ) attributes.get('cardtype ); //月卡类型
JSONarraySubitems=(JSONarray ) obresult2.getjsonarray ) (subitems );
jsonobjectsubitems0=(JSON对象) subitems.get(0;
jsonobjectAttributes1=(JSON object ) subitems0.get ) (attributes );
intmonthperiod0=(int ) Attributes1.get ) (monthperiod ); //月卡收费周期
双门0=(双门)属性1.get ) )门); //月卡收费标准
feestandard.set card type (card type 0;
feestandard.setMoney(Money0;
feestandard.setmonthperiod (month period 0;
fee标准. add (feestandard; }
注: jsonObject和jsonObject都是JSON对象,但必须在不同的对象中接受它们才能检索对象中的元素。
string results=entity utils.tostring (response.get entity ();
jsonobjectjson=newjsonparser (.parse (results ).getAsJsonObject );
intresult code=JSON.get (result code ) ).getAsInt );
if (结果代码==0) {
jsonelementdataitems=JSON.get (数据项);
}
来自JSON对象get的元素由JsonElement承担。
jsonobjectpartone=JSON 01.getjsonobject (' attributes );
stringOrderno=(string ) Partone.get ) ) orderno ); //订单编号
stringcarno1=(string ) Partone.get(carno ); //号码
String totalFee=(String ) partone.get('totalfee ); //总费用
来自JSONObject get的元素由字符串承担。