json解析问题 用java语言

现在服务器发来形如
{"ret_val":0,
"pay_url":"https://qr.95516.com/00010001/62034325710998146707413908014385",
"OrderID":"HF0050545815180409161523725999"}
这样的json数据,
我如何得到每个属性的值呢?

24个回答

可以通过json的jar包进行解析
public class JSONTest {
public static void main(String[] args) {
String sTotalString = "[{id:'001',name:'张三',age:'32'},{id:'002',name:'张四',age:'11'},{id:'003',name:'张五',age:'20'}]";
try {
// 把字符串转换为JSONArray对象
JSONArray jsonArray = JSONArray.fromObject(sTotalString);
if(jsonArray.size() > 0){
// 遍历 jsonarray 数组,把每一个对象转成 json 对象
for(int i = 0; i < jsonArray.size(); i++){
JSONObject jsonObject = jsonArray.getJSONObject(i);
System.out.println(jsonObject.get("id"));
System.out.println(jsonObject.get("name"));
System.out.println(jsonObject.get("age"));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

JSONObject jsonobject = JSONObject.parseJSON(<你的json串>);
jsonobject.get();

接受到的数据应该是Object类型的,通过JSONObject.fromObject()来转成JSON类型,通过getString()可以取到值,另外还有许多插件如gson等可以处理json对象

或者在页面解析//JSON.parse()这个方法的输出结果同样为30
var evals='{"张三":30,"李四":25}';
var jsonObject=JSON.parse(evals);
alert(jsonObject.张三);

如果你用String接收的这个信息:
比如用“json”字段接收
1.// String转换成jsonArray或者jsonObject 如果是数组类型用array对象类型用object,看您的情况用object
JSONObject obj = JSONObject.fromObject(json);
//然后用个体方法根据key取值
String val = obj.getString("ret_val");
String url = obj.getString("pay_url");
希望对你有帮助
json包是net.st的别倒错

JSONArray jsonArray = JSONArray.fromObject(json字符串);转换下,循环取值

String转换成jsonArray或者jsonObject 如果是数组类型用array对象类型用object,看您的情况用object
JSONObject obj = JSONObject.fromObject(json)

JSONObject json = JSONObject.fromObject(jsonStr);
String ret_val=json.getString("ret_val"));

...类似

//获得上面的json字串Str
// 将json字符串转化Json对象
JSONObject json = JSONObject.parseObject(str);
String retval=json.getString("ret_val");
String payUrl=json.getString("pay_url");
String orderId=json.getString("OrderID");

你可以通过fastjson框架来实现

共24条数据 1 3 尾页
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
java语言JSON解析包,全部7个包
java语言JSON解析包,全部7个包,少了一个包都不行哦。
php用json解析相关问题请教
初次使用php做json解析。rnrna.php 打印出来内容如下rn[code=PHP]"name":"bigsea","id":2[/code]rnrn需要用b.php解析出name 和id的值。rnrnb.php文件如下:[code=PHP]rn$subjectjson = file_get_contents('http://192.168.0.18/a.php');rn rn $subjectdetail = json_decode($subjectjson);rn$subject = $subjectdetail -> name;rn//主题信息rnecho "name:".$subject -> name.' ';rn[/code]rnrn现在的问题是b.php解析不出来name的值。请各位高人指教怎么搞的。
用反射完成Json解析
前言: Json解析工具已经有一大堆一大堆得了,为什么还要多此一举,自己写一个出来呢? 主要的原因是:大量的Json解析工具都不检查重复引用。一旦出现A中包含B,B中包含A这样的情况(在工作中是经常出现的!)就会崩溃! 这个工具类首先完成了对重复性的检查。除此之外呢,就是对我个人来说的额外原因了:容易扩展。 毕竟自己写的代码,想咋扩咋扩,比起读那些工具类的源码真是轻松太多了,让解析效率见鬼
用JavaBean解析返回的JSON
本课程是兼顾框架0基础使用,框架源码实现,框架封装的课程。
php json解析问题
[code=PHP]"FUID":"1344570006238357","photourl":"http://xxx.xxxx.com/xxxx/1344570010816293.png","NickName":"123456","Content":"","rtime":"2012-08-19 16:16:07"[/code]rn转换成json时,是没有问题的,但是转换回来就会出错,只要里面出现Content这种内容就转换不回来?
求教JSON解析问题
小弟对刚了解JSON,刚练手就碰到个问题,如下:rnjava后台返回的JSON字符串是'name':'test','remark':'描述'这种到前台可以正常解析,没有问题。rn可是'name':'test','remark':''描述1有单引号''这时一到前台走到这一句 var obj = eval('(' + json + ')');rn就报错了,下面的JS就执行不了。 因为那个remark的值不是固定的,有的有单引号,有的没有,现在不知道怎么办了。rn求高手赐教。json返回字符串有单引号或者特殊字符该怎么办?rn谢谢!
json解析的问题
rnrn使用json对从google字典里面获取的数据进行解析,老是报错,进过查证,发现是在获取下来的数据中包含了字符 "\"rn这个问题要怎么解决呢? 貌似是json库的问题。。。因为android的自带json不会有这个问题!!!!rnrnrnrnrn求高人来解答阿
SliverLight 解析 Json 的问题
你好,我在 SliverLight 项目中需要去解析一个 ASP.NET WebApi服务提供的json数据。rn直接浏览 WebApi 服务 Uri 显示数据如下:rnrn----------------------------------------------------------------------------------------------------------------------------------------rnThis XML file does not appear to have any style information associated with it. The document tree is shown below.rnrnrnGroceriesrn1rnArthur Janrn1.39rnrnrn----------------------------------------------------------------------------------------------------------------------------------------rnrnSliverLight 解析 JSON 相关程序代码如下:rnrn----------------------------------------------------------------------------------------------------------------------------------------rnvar buffer = System.Text.Encoding.UTF8.GetBytes(e.Result);rnvar ms = new MemoryStream(buffer);rnvar jsonObject = System.Json.JsonObject.Load(ms) as System.Json.JsonObject;rnrntextBox1.Text = e.Result + "\r\n";rntextBox1.Text += string.Format("代号:0,名称:1,分类:2,价格:3",rn jsonObject["Id"].ToString(),rn jsonObject["Category"].ToString(),rn jsonObject["Name"].ToString(),rn jsonObject["Price"].ToString()rn );rn----------------------------------------------------------------------------------------------------------------------------------------rnrne.Result 显示的数据如下:rnrn["Id":1,"Name":"Arthur Jan","Category":"Groceries","Price":1.39]rnrn但是 VS2010 却会在 以下程序区段出现错误:rnrn-----------------------------------------------------------------------rntextBox1.Text += string.Format("代号:0,名称:1,分类:2,价格:3",rn jsonObject["Id"].ToString(),rn jsonObject["Category"].ToString(),rn jsonObject["Name"].ToString(),rn jsonObject["Price"].ToString()rn );rn-----------------------------------------------------------------------rn错误讯息如下:rn[img=http://img.my.csdn.net/uploads/201303/04/1362385323_1954.gif][/img]rnrn感谢回应。
Json解析问题JsonArray
"text":["水水水水"] 这样的jsonarray如何解析成string,获得”水水水“
json的解析问题
此博文以下列的json数据为例,讲解json转换或解析经常遇到的问题。 { &amp;amp;amp;quot;success&amp;amp;amp;quot;: true, &amp;amp;amp;quot;resultMessage&amp;amp;amp;quot;: &amp;amp;amp;quot;&amp;amp;amp;quot;, &amp;amp;amp;quot;result&amp;amp;amp;quot;: [{ &amp;amp;amp;quot;code&amp
json解析的转换问题
报错:com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $我的实体类是从我自己的ssm项目中直接拷贝,所以应该没有问题。处理方法:之前一直没搞懂gson的用法。若返回的是一个对象...
json解析问题
["\"id\":\"4039\",\"acceptDeptName\":\"一区\",\"name\":\"赵芳\",\"acceptDept\":\"2010104\",\"claimItem\":\"6439\",\"createDate\":\"2013-04-02 14:08:15\",\"claimoperator\":\"30156\",\"claimName\":\"王群\"","\"id\":\"4018\",\"acceptDeptName\":\"二区\",\"name\":\"张嵊鹏\",\"acceptDept\":\"2010103\",\"claimItem\":\"8423\",\"createDate\":\"2013-04-02 08:12:32\",\"claimoperator\":\"30195\",\"claimName\":\"金颖\""]rn这段是我想要解析的。rntry rn JSONArray arr = new JSONArray(rs);rn for (int i = 0; i < arr.length(); i++) rn Log.i("", "JSONArray.length()--===" + arr.length());rn //执行到下面这两句时会直接跳Exceptionrn JSONObject ob = arr.getJSONObject(i);rn app = MobicPick.parseApp(ob);
JSON解析 问题
JSON解析 rnrnjson 同一个接口,有时返回rnrn"recommend": [],rnrn有时返回rnrn "recommend": rnrn不能用泛型怎么解析。
JSON解析出现了问题
获取了一个JSON,无法解析。rnrn代码:rnrn [httpClient postPath:@"" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) rn NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:responseObject options:kNilOptions error:nil];rn NSLog(@"%@",jsonDict);rn rn NSArray *jsonArray = [jsonDict objectForKey:@"sJSON"];rn NSLog(@"%@",[jsonArray class]);rn NSLog(@"%@",jsonArray);rnrnNSLog打印类给出的_NSCFString类。rnrn是不是这不是JSON?不过看上去真的很像。rnrn ["ImageTagID":78,"Xpixel":408,"Ypixel":69,"Xpercent":17]
关于Json解析的问题
Json解析的参数名,不能改变
有关JSON解析的问题
对方用PHP的json_encode生成[[aaa,bbb],[ccc,ddd]]这样的json字符串。rnrn我是用c#解析的,我想定义一个类,然后直接通过JsonConvert.Import转换过来,可总是提示“Cannot import test.datas from a JSON Array value.”rnrn下面是类的定义:rn public class datasrn rn public data1[] Stockdata; 作为一级数组rn rnrn public class data1rn rn public data2[] Stockinfo; 作为二级数组rn rnrn public class data2rn rn public string data; 最里面的数据rn rnrn然后通过下面的方式调用:rnrn(datas)JsonConvert.Import(typeof(datas), test1) '字符串变量test1存放的就是上面的json字符串。rnrn第一次接触json,请帮忙指出这里什么的错误。或是有什么更好的办法来解决么?谢谢!
android JSON解析问题
public static List getAllNewsFromNetwork(Context context) rn final List list = new ArrayList();rn RequestQueue queue = Volley.newRequestQueue(context);rnrn final JsonObjectRequest request = new JsonObjectRequest(URL, null, new Response.Listener() rn @Overridern public void onResponse(JSONObject response) rn Log.e(TAG, "response: " + response);rn try rn JSONObject result = response.getJSONObject("result");rn JSONArray array = result.getJSONArray("data");rn Log.e(TAG, "array: " + array);rn for (int i = 0, len = array.length(); i < len; i++) rn JSONObject object = (JSONObject) array.opt(i);rn Log.e(TAG, "object: " + object);rn NewsInfo info = new NewsInfo();rn info.setTitle(object.getString("title"));rn info.setThumbnail_pic_s(object.getString("thumbnail_pic_s"));rn info.setThumbnail_pic_s02(object.getString("thumbnail_pic_s02"));rn info.setThumbnail_pic_s03(object.getString("thumbnail_pic_s03"));rn info.setDate(object.getString("date"));rn info.setType(object.getString("realtype"));rn info.setUrl(object.getString("url"));rn Log.e(TAG, "onResponse: info.toString() ==" + info.toString());rn list.add(info);rn rn catch (Exception e) rn e.printStackTrace();rn rnrn rn , new Response.ErrorListener() rn @Overridern public void onErrorResponse(VolleyError error) rn Log.e(TAG, "onErrorResponse: " + error);rn rn );rn queue.add(request);rn queue.start();rn Log.e(TAG, "getAllNewsFromNetwork: list.size() ==" + list.size());rn return list;rn rnrn 这个函数返回的list为什么是空的?response输出的数据一直都有,解析也没出现问题,rn求大神指教
go 的json解析问题
type Message struct rn Name stringrn Body stringrn Time int64rn Parents *ParentSrnrnrntype ParentS structrn father stringrn mother stringrnrnrn pp := &ParentS"Zhang","li"rn rn rn m := Message"Alice", "Hello", 1294706395881547000,pprnrn fmt.Println("father is",m.Parents.father)rn rn x, err := json.Marshal(m)rn if err != nil rn fmt.Printf("error is %v\n", err)rn else rn fmt.Printf("解析=%s",x)rn rnrnrn///////////////////////////////输出怎样出现了 空???如下:rnfather is Zhangrn解析="Name":"Alice","Body":"Hello","Time":1294706395881547000,"Parents":rn
JSON的解析问题
["cateid":1,"cateurl":"/image03/1.png","catetitle":"HAM火锅","cateprice":"88元","cateid":2,"cateurl":"/image03/2.png","catetitle":"朱师傅老母鸡滋补火锅","cateprice":"78元","cateid":3,"cateurl":"/image03/3.png","catetitle":"燕家厨房","cateprice":"178元"]rnrnrn这段JSON怎么解析,用JSONObject。这个JSON数据,没有key...........
json 字符串解析问题
从接口中获取的json字符串前面多出了个“1ff8” 后面多出了个“ 0”rn用什么方法怎么来解析它呢?
C++的JSON解析问题
[code=c]rnrn "version": "3",rn "processFile": "",rn "processMainData": rn "start1453967094591": rn "formDefine": ,rn "annexDefine": ,rn "CONDITION": "true",rn "LABEL": "开始",rn "name": "start"rn ,rn "businessActivity14539670945922": rn "id": "businessActivity14539670945922",rn "type": "businessActivity",rn "CONDITION": "true",rn "LABEL": "项目讯息",rn "name": "businessActivity2"rn rn ,rnrn[/code]rn由于"start1453967094591"和"businessActivity14539670945922"节点内容是随机的,怎么遍历到每个"LABEL"
JSON解析问题集锦
NSJSONSerialization精度丢失问题 当我们服务器传一个数据3.0(浮点数)Android那边也是3.0,iOS这边却是是2.99999 // 模拟服务器传递过来的JSON数据 NSString *jsonStr = @&quot;{\&quot;71.40\&quot;:71.40, \&quot;97.40\&quot;:97.40, \&quot;80.40\&quot;:80.40, \&quot;188.40\&quot;:188.40}&quot;; ...
关于json解析的问题
"code":"00",rn"id":"num":"0","istarget":"false",rn"mail":"num":"1","istarget":"true",rn"cell":"num":"1","istarget":"false",rn"name":"num":0,rn"addr":"num":1,rn"commodity":,rn"media":"财经":"num":"2.0","历史/社会/人文":"num":"1.0","科学/教育":"num":"2.0",rn"ec":"3C 数码": "num": "9","level1": "0.6183662429189318","price": "536.2",rn"运动娱乐": "num": "284","level1": "0.9798223497689971","price": "2746.9"rnrnrn请问怎么解析这个json,上面的能读出来,但是media和ec这两个不知道怎么建类rnrn我用的DataContractJsonSerializer
json解析格式问题。。。。。
如何解析对象嵌套对象的json数据格式,或者说怎么转化为json数组
一个JSON解析问题。
有一个json对象如下rn myjson="anchor1":[1,2,3,4,5],"anchor2":[6,7,8,9,10]rn请问在客户端的Javascript函数里怎样解析出数组来?
Json解析问题
服务器那边有数据时返回 [code=java]rn "status": 1,rn "result": rn "unit": [rn rn "unitType": 1,rn "name": "博乒网总站",rn "id": "8435817f66f84841b344e5108bbe788b"rn ,rn rn "unitType": 2,rn "name": "威赛体育",rn "id": "b5721e6ca5a54b20afdd7f74e33d547e"rn rn ]rn rn[/code]rnrn没有数据时返回[code=java]rn "status": 1,rn "result": rn "unit": rn rn[/code]rnrn我一直在用GSON做解析,所以事先设置好实体类就可以对应解析,但是这种情况,对象或者数组不明确应该怎么办呢?rn我知道应该可以使用JSONObject.optJSONArray 或者JSONArray.optJSONObject 来做判断就可以手动解析了,但是这样做很浪费时间,有没有其他解决办法呢?
json 解析问题
rn "status":"OK",rn "result":rn "location":rn "lng":116.307175,rn "lat":40.057098rn ,rn "precise":1,rn "confidence":80,rn "level":"\u9053\u8def"rn rnrn这是调用百度借口返回的json数据,用什么格式解析它啊! Map "result"的的值解析不了。rn Map> "status"、"precise"这样的值解析不了。 该用什么格式,求指点。
跪求json解析问题
我用Newtonsoft在C#后台生成一组json,到了前端用eval解析报错,json字符串是"\r\n \"data\": [\r\n \r\n \"OBJECTID\": \"10574daolu\",\r\n \"NAME\": \"水厂二路\",\r\n \"isSensitive\": 0,\r\n \"isFix\": 0\r\n ,\r\n \r\n \"OBJECTID\": \"10995daolu\",\r\n \"NAME\": \"水厂一路\",\r\n \"isSensitive\": 0,\r\n \"isFix\": 0\r\n ,\r\n \r\n \"OBJECTID\": \"249lukou\",\r\n \"NAME\": \"解放大道(水厂二路路口)C\",\r\n \"isSensitive\": 0,\r\n \"isFix\": 0\r\n ,\r\n \r\n \"OBJECTID\": \"377lukou\",\r\n \"NAME\": \"友谊大道(水厂路路口)\",\r\n \"isSensitive\": 0,\r\n \"isFix\": 0\r\n \r\n ]\r\n"这样的,我用replace("\r\n","")把\r\n去掉了,但是\"如何转成",怎么才能让eval直接解析成json对象呢?
json的时间格式解析问题
[code=C#]rnJavaScriptSerializer serializer = new JavaScriptSerializer();rn string jasonString = serializer.Serialize(messages);rn[/code]rn得到jasonString = “["Content":"is it true???","Eventdate":"\/[color=#FF0000]Date(1297699200000)[/color]\/","Avatar":"Upload/default.jpg","Username":"xiaoxin321","Url":"xxx"]”rnrnmessages是一个对象,rn这段时间如何处理才能得到正确的时间?
PHP的JSON解析问题
[code=php]"type":"success","code":0,"message":null,"data":"box_list":[rn"boxId":"cfce938f2c7c11e69d5700000a00191c","boxNum":"nantong_test1","boxName":"我的保险柜","boxIp":"","boxMac":"","powerStatus":"0","networkStatus":"0","doorStatus":"2","shakeInfo":"1","deviceStatus":"1","boxStatus":"1","verifyStatus":"","lockPwd":"ABCD07033132333435363F030D","boxVersion":0,"channelId":"nantong_test1","boxControlPwd":"874d05d4bdd9077a7aefa0dc8c8cbd1f","adminUserId":"62f199be303b11e684c000000a00191c","boxPhone":"","defaultSkin":"0","netWorkName":"","agentId":"","createTime":null,"warninhCount":0,"batteryLevel":null,"temp":null,rn"boxId":"73b1a2932c7211e69d5700000a00191c","boxNum":"lvlei6","boxName":"我的保险柜","boxIp":"","boxMac":"","powerStatus":"0","networkStatus":"0","doorStatus":"2","shakeInfo":"1","deviceStatus":"1","boxStatus":"1","verifyStatus":"","lockPwd":"ABCD07033132333435363F030D","boxVersion":30,"channelId":"lvlei6","boxControlPwd":"874d05d4bdd9077a7aefa0dc8c8cbd1f","adminUserId":"31f674062c8311e69d5700000a00191c","boxPhone":"","defaultSkin":"0","netWorkName":"","agentId":"","createTime":null,"warninhCount":0,"batteryLevel":null,"temp":nullrn]rn,"user":"id":"296d4ecc303d11e684c000000a00191c","userName":"kaka","loginName":"12@qq.com","loginPwd":"874d05d4bdd9077a7aefa0dc8c8cbd1f","userFinger1":"","userFinger2":"","userFinger3":"","type":"0","userPhone":"","userPhoto":"http://hissdata.blob.core.chinacloudapi.cn/userpicdata/296d4ecc303d11e684c000000a00191c_1465717285898.png","channelId":"","userListenDate":1465694992000,"boxNum":"","controlPwd":"","userNum":"","userAddress":"","userMail":"12@qq.com"[/code]rnrn要获取box_list中的所有下标下的数据,rn我的获取方式$c = $data['data']['box_list'][0]['boxId']; 但是不知为何获取到的是73b1a2932c7211e69d5700000a00191c 也就是box_list中下标为1的boxId。也仅仅只能获取这个 。rn求大神!!!!!!!rn求大神!!!!!!!rn求大神!!!!!!!rn
JSON解析问题
JSON String :rnrn "errno": 0,rn "info": rn [color=#FF0000]"10"[/color]: [rn rn "ad_id": "1",rn "com_id": "10",rn "pr_id": "0",rn "name": "部门1",rn "info": ""rn ,rn rn "ad_id": "2",rn "com_id": "10",rn "pr_id": "1",rn "name": "部门2",rn "info": ""rn ,rn rn "ad_id": "3",rn "com_id": "10",rn "pr_id": "1",rn "name": "部门3",rn "info": ""rn rn ]rn rnrn这是通过http post返回的值,为了便于理解,通过Newtonsoft.Json.dll中的方法转换为了object。如果没有红色部分,可用下面的形式得到对象rn需要的对象rn[code=csharp]rn public class Rtn1rn rn public string errno;rn public dept info = new dept();rn rn public class deptrn rn public string ad_id;rn public string com_id;rn public string pr_id;rn public string name;rn public string info; rn rn[/code]rn在post返回后,strRtn为Json字符串rn[code=csharp]rnRtn1 rtn = (Rtn1)JsonConvert.DeserializeObject(strRtn,typeof(Rtn1));rn[/code]rnrn但是,问题中这个的Json格式,其中的“10”,为com_id,是一个值。目前只有一个“10”,在未来可能还会有“11”,“12”,等等。rn我想问问,对于这种格式的Json字符串,怎么能够解析成对象??rnrn望明白人士,给予解答,谢谢!!rn[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/onion/74.gif][/img][img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/onion/74.gif][/img][img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/onion/74.gif][/img][img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/onion/74.gif][/img][img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/onion/74.gif][/img]
asp.net Json的解析问题?
使用Newtonsoft.Json.dll把一个datatable解析成json格式的字符串:(如下)rn"page":"1","totalcount":"20",rn "rows":[rn rn "id":"1",rn "cell":["1","aaaaaaa","ccccccccc"]rn ,rn rn "id":"2",rn "cell":["2","bbbbbbbbb","gsdgsdgds"]rn ,rn rn "id":"3",rn "cell":["3","sgdsgsdgd","sgdsgsgds"]rn rn ]rnrn生成的这个json字符串在前台用jquery 1.4.1如何解析??rnrnrn
json解析问题,求解
[code=html]["name":"rpd","id":255,"type":"MONITOR","available":true,"unitId":1,"ip":"99.7.7.243","name":"jiankong","id":1873,"type":"MONITOR","available":true,"unitId":1,"ip":"99.7.7.233","name":"monitor rpd","id":259,"type":"MONITOR","available":true,"unitId":1,"ip":"99.7.7.241","name":"总行1604V","id":174,"type":"HDX","available":true,"unitId":1,"ip":"99.7.7.134","name":"总行1603V","id":2270,"type":"HDX","available":true,"unitId":1,"ip":"99.7.7.133","name":"总行1602V","id":2268,"type":"HDX","available":true,"unitId":1,"ip":"99.7.7.132","name":"研发六楼603","id":2187,"type":"HDX","available":true,"unitId":1,"ip":"99.1.113.61","name":"上海金融","id":2189,"type":"HDX","available":true,"unitId":1,"ip":"99.14.64.231"]rn[/code]rn以上是json数据rnrn[code=java]rnpublic class EndpointInfo rn rn rn long id;rn String type;rn String name;rn String ip;rn boolean available;rn long unitId;rn rn public long getId() rn return id;rn rn public void setId(long id) rn this.id = id;rn rn public long getUnitId() rn return unitId;rn rn public void setUnitId(long unitId) rn this.unitId = unitId;rn rn public String getType() rn return type;rn rn public void setType(String type) rn this.type = type;rn rn public String getName() rn return name;rn rn public void setName(String name) rn this.name = name;rn rn public String getIp() rn return ip;rn rn public void setIp(String ip) rn this.ip = ip;rn rn public boolean getAvailable() rn return available;rn rn public void setAvailable(boolean available) rn this.available = available;rn rn rnrn[/code]rn我对应的bean类rnrnrn[code=java]rnprivate static ArrayList m_endpointinfolist = null;rnType typeoft = new TypeToken>().getType();rnm_endpointinfolist = gson.fromJson(sb.toString(),typeoft);rn[/code]rnrn[code=java]rnprivate static final ObjectMapper mapper = new ObjectMapper();rnprivate static ArrayList m_endpointinfolist = null;rnprivate static ArrayList m_endpointinfolist = null;rnm_endpointinfolist = mapper.readValue(sb.toString(), new TypeReference>());rn[/code]rn以上是使用的2个包,debug都是可以顺利解析的,但是我打包成jar之后就会出现异常rnrnrnrn
关于json解析问题
[code=objc]NSURL *url=[NSURL URLWithString:@"http://192.168.1.101/website1/studentinfo.ashx?sno=sno20130811002"];rn NSError *error;rn NSURLRequest *request=[NSURLRequest requestWithURL:url];rn NSData *data=[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];rn NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];rn NSDictionary *dic_student=[dic objectForKey:@"StudentInfo"];rn NSLog(@"Result:%@",dic_student);rn[/code]rnrn打印字典dic_student 输出:rnResult:(rn rn Sage = 23;rn Sdept = "\U73af\U5883\U5de5\U7a0b";rn Sname = zhanghuan;rn Sno = SNO20130811002;rn Spec = "\U73af\U5883\U5b89\U5168";rn Ssex = "\U7537";rn rn)rn此时dic_student字典里面的键值访问不到为什么呢? 字典的allKeys为空,里面的学号姓名等属性都访问不到rn
json串解析问题
最近工作中涉及到json串的解析,所以将解决办法贴在这里。 调用openstack  API后,返回的信息是json字符串,这就需要json串解析来获取我想要的信息 网上查了一些解决办法,现在说说我所采用的办法,使用的jar包为json.jar json串分以下这些情况 1 字段值就是要获取的值,如{"name":"tom"} ,使用  JSONObject json = new
关于json的解析问题
$id = $this->input->post('program_id');rn $related_change = json_decode($this->input->post('related_change'));rn $data = array(rn 'user_key' => $related_change('user_key'),rn 'channel_id' => $related_change('channel_id'),rn 'date' => $related_change('date'),rn 'program' => array(rn 'name' => $related_change->('program_name'),rn 'type' => $related_change('program_type'), rn 'start_time' => date('Y-m-d H:i:s', $related_change('program_start_timestamp')),rn 'end_time' => date('Y-m-d H:i:s', $related_change('program_end_timestamp')),rn 'duration' => (int)$related_change('program_end_timestamp') - (int)$related_change('program_start_timestamp'), rn 'source_duration' => time_to_sec($related_change('program_original_duration')),rn 'source_type' => (string)$related_change('src_type'),rn 'source_start_ts' => $related_change('src_start_time')rn 'uri' => (string)$related_change('program_uri'), rn )rn );rnrnrnrn这一块数据是解析的不对的rnrn它们不是从 $thi->input->post 里面出来的, 而是从 $related_change 里面来的rnrn该怎么写?
一个JSON解析问题
有一个json对象如下 rn myjson="anchor1":[1,2,3,4,5],"anchor2":[6,7,8,9,10] rn请问在客户端的Javascript函数里怎样解析出数组来?
json解析后的问题
ajax解析json数据后 怎么把解析后的数据放在一个文本框中啊 。。rnrnrn我已经用 document.form名.文本框的name.value 都放不进去;
JSON传递解析的问题
各位大神 你们好 在这里 求大家帮助我 直接点吧 我有一个从前段传递java中的json的值,需要解析该json,当中是提示错误,不解......rn[code=javascript]rn batchDeletionGameSkinServer:function()rn var me = this;rn var grid = me.getGameSkinServiceGrid(); //获取表单变量的对象rn var selected = grid.getSelectionModel().getSelection();rn [color=#FF0000] var skinId = [];[/color]rn if (selected == null || selected.length <= 0) rn Ext.ux.Toast.msg("温馨提示", "请先选择要删除的专题信息");rn return;rn rn ;rn for(var i = 0; i < selected.length; i++) rn if (selected[i].data != null)rn [color=#FF0000]skinId.push(selected[i].data.skinId);[/color]rn rn rn [color=#FF0000]var record = selected,rn params = 'skinId': skinId;[/color]rn Ext.MessageBox.confirm('温馨提示', '确定删除该客服信息吗?', function (btn) rn if (btn == 'yes') rn me.getStore().remove(record);rnrn Ext.Ajax.request(rn url: './rs/skin/batchDeletionGameSkin',rn [color=#FF0000] jsonData: Ext.JSON.encode(params),[/color]rn method: 'POST',rn success: function (response, opts) rn Ext.ux.Toast.msg("温馨提示", "删除成功!");rn me.getStore().load();rn grid.getSelectionModel().deselectAll();rn ,rn exception: function (response, opts) rn var json = Ext.decode(response.responseText);rn Ext.ux.Toast.msg("温馨提示", json.message);rn rn );rn else rn return;rn rn );rn ,rn[/code]rnrn这部分是前段传递值的部分,再看看传递的java部分rn[code=java]rn@Path("batchDeletionGameSkin")rn @POSTrn @JsonProperty("skinId")rn public IServiceResponse batchDeletionGameSkinAction(String skinId)rnrn ResponseStatus responseStatus = new ResponseStatus();rn RespMobileSkinDelMaster resp = new RespMobileSkinDelMaster();rn SkinEO skinEO = new SkinEO();rnrn JSONObject jsonObject = JSONObject.fromObject(skinId);rn JSONArray jsonArray = JSONArray.fromObject(jsonObject);rn [color=#FF0000]List listArray = (List)rn JSONArray.toCollection(jsonArray, BatchDeletionRequest.class);[/color]rn[/code]rn代码在最后一部分就不保找不到类型匹配的错误rn我的封装类是rn[code=java]rnpublic class BatchDeletionRequest extends AbstractServiceResponse rn private String skinId;rnrn public String getTopicNo() rn return skinId;rn rnrn public void setTopicNo(String topicNo) rn this.skinId = topicNo;rn rnrn[/code]rnrn希望大家帮帮我 不胜感激
WCF 解析 JSON 问题
接口定义rnrn [OperationContract]rn [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, UriTemplate = "/Send")]rn [Description("信息发布")]rn Model.Message.Task Send(string UserName, string Password, object Data)rnrn接口实现rnpublic Model.Message.Task Send(string UserName, string Password, object Data)rnrn //根据用户名和密码解析Data(Data是JSON字符串,不同的用户名和密码Data内容不同)rn rnrnrn客户端提交示例1rnrnrn"UserName":"test",rn"Password":"123456",rn"Data":"a":"1",rnrnrn客户端提交示例2rnrnrn"UserName":"test",rn"Password":"123456",rn"Data":"a":"1","b":"2",rnrnrn客户端提交示例3rnrn"UserName":"test",rn"Password":"123456",rn"Data":"c":"3",rnrn.........rnrnrnWCF定义接口如何指定一个参数为匿名类型,使用Object类型好像不行,最终想要达到的目的是rnrnpublic Model.Message.Task Send(string UserName, string Password, object Data)rnrn //例如示例1,Data = "Data":"a":"1";rn //例如示例2,Data = "Data":"a":"1","b":"2";rn //例如示例3,Data = "Data":"c":"3"rn 然后根据用户名和密码的不同使用不同的对象来序列化Datarn
相关热词 c#部署端口监听项目、 c#接口中的属性使用方法 c# 昨天 c#func链接匿名方法 c#怎么创建文件夹 c#从键盘接收空格 c#da/ad c#部门请假管理系统 c#服务器socket c# 默认的访问修饰符