jsonobject

Android ArrayAdapter and JSONArray

↘锁芯ラ 提交于 2019-12-01 02:10:16
I am new to Android Development. I purely like to work with JSON Objects and Arrays for my simple application considering the lightness of the JSON Carrier compared to XMLs. I had challenges with ArrayAdapter to populate the ListView. This is how I overcome and need your suggestions on it. Extend the Adaptor class. Then pass the JSONArray to the constructor. Here the constructor calls super with dummy String array setting the length of the JSONArray. Store the constructor arguments in class for further use. public myAdaptor(Context context, int resource, JSONArray array) { super(context,

java基础之泛型对象与json互转

[亡魂溺海] 提交于 2019-11-30 23:36:58
1. 场景描述 把泛型对象转成字符串放到缓存中,获取后使用有点问题,记录下,有碰到的朋友,参考下。 2. 解决方案 2.1 操作类及说明 /** * @auther: 软件老王 */ public static void main(String[] args) { VO<UserParm> vo = new VO<UserParm>(); UserParm user = new UserParm(); user.setUserIdName("1111"); user.setMobilePhoneNo("2222"); vo.setData(user); //正常情况 //1.对象转json str String str = JSONObject.toJSONString(vo); System.out.println(str); //2,json str 转对象 VO vojs= JSONObject.parseObject(str,VO.class); System.out.println(vojs); //泛型 不能使用强转,不管用,报错 VO<UserParm> vojs2= JSONObject.parseObject(str,VO.class); System.out.println(vojs2); // System.out.println(vojs2.getData(

Converting String to Android JSONObject loses utf-8

痞子三分冷 提交于 2019-11-30 23:03:13
I am trying to get a (JSON formatted) String from a URL and consume it as a Json object. I lose UTF-8 encoding when I convert the String to JSONObject. This is The function I use to connect to the url and get the string: private static String getUrlContents(String theUrl) { StringBuilder content = new StringBuilder(); try { URL url = new URL(theUrl); URLConnection urlConnection = url.openConnection(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); String line; while ((line = bufferedReader.readLine()) != null) { content.append(line +

HttpClient的几种请求方式

☆樱花仙子☆ 提交于 2019-11-30 22:00:44
public static String doPostToken(String tokenUrl,String clientId,String clientSecret,String grantType) { CloseableHttpResponse response = null; String resultToken = ""; try { //1.创建Httpclient对象 CloseableHttpClient httpClient = HttpClients.createDefault(); //2.创建Http Post请求 HttpPost httpPost = new HttpPost(tokenUrl); //3.封装请求参数 List<BasicNameValuePair> list = new ArrayList<>(); list.add(new BasicNameValuePair("client_id", clientId)); list.add(new BasicNameValuePair("client_secret", clientSecret)); list.add(new BasicNameValuePair("grant_type", grantType)); httpPost.setEntity(new

Android ArrayAdapter and JSONArray

我是研究僧i 提交于 2019-11-30 20:46:34
问题 I am new to Android Development. I purely like to work with JSON Objects and Arrays for my simple application considering the lightness of the JSON Carrier compared to XMLs. I had challenges with ArrayAdapter to populate the ListView. This is how I overcome and need your suggestions on it. Extend the Adaptor class. Then pass the JSONArray to the constructor. Here the constructor calls super with dummy String array setting the length of the JSONArray. Store the constructor arguments in class

微信授权登陆

折月煮酒 提交于 2019-11-30 19:35:18
package com.ctrl.aWxSpLogin; import com.alibaba.fastjson.JSONObject; import com.ctrl.mobile.respUtils.HttpUtil; import com.thinkgem.jeesite.common.config.Global; import java.util.HashMap; import java.util.Map; /** * @Author LiPeiMin * @Description //TODO * @Date 11:52 2019/11/18 **/ public class SpLogin { /** * 开发者设置中的appId */ private static String appId; /** * 开发者设置中的appSecret */ private static String secret; static { try { appId = Global.getConfig("sp.appId"); secret = Global.getConfig("sp.secret"); } catch (java.lang.Exception e) { e.printStackTrace(); } } /** * @return com.alibaba.fastjson

使用Jersey构建图片服务器

孤街浪徒 提交于 2019-11-30 17:58:25
使用Jersey构建图片服务器 前台页面代码 <form id="jvForm" action="add.do" method="post" enctype="multipart/form-data"> <table> <tr> <td width="20%" class="pn-flabel pn-flabel-h"></td> <td width="80%" class="pn-fcontent"> <img width="100" height="100" id="allImgUrl" /> <input type="hidden" name="imgUrl" id="path" /> <input type="file" onchange="uploadPic()" name="pic" id="logoPic"/> </td> </tr> </table> </form> 前台JS代码 <script type="text/javascript"> //上传图片 function uploadPic() { //定义参数 var options = { url : "/upload/uploadPic.do", dataType : "json", type : "post", beforeSubmit : function(formData,jqForm,options

Android之JSON的三种解析方式

半城伤御伤魂 提交于 2019-11-30 15:16:22
一、什么是JSON? JSON是一种取代XML的数据结构,和xml相比,它更小巧但描述能力却不差,由于它的小巧所以网络传输数据将减少更多流量从而加快速度。 JSON就是一串字符串 只不过元素会使用特定的符号标注。 {} 双括号表示对象 [] 中括号表示数组 "" 双引号内是属性或值 : 冒号表示后者是前者的值(这个值可以是字符串、数字、也可以是另一个数组或对象) 所以 {"name": "Michael"} 可以理解为是一个包含name为Michael的对象 而[{"name": "Michael"},{"name": "Jerry"}]就表示包含两个对象的数组 当然了,你也可以使用{"name":["Michael","Jerry"]}来简化上面一部,这是一个拥有一个name数组的对象 二、JSON解析之传统的JSON解析 1、生成JSOn字符串 ? 1 2 3 4 5 public static String createJsonString(String key, Object value) { JSONObject jsonObject = new JSONObject(); jsonObject.put(key, value); return jsonObject.toString(); } 2、解析JSON字符串 分为以下三种情况,一个 Java Bean

js与java对json的操作

雨燕双飞 提交于 2019-11-30 15:15:28
JSON呢,是现在大部分,并且主流的传递数据的方式。 今天讲一下javascript的java对json的操作 提到js,当下就有一个比较主流的插件,vue.js,这个插件程序员没用过也都听说过吧, 非常方便的一个js插件,像js对于json的操作比如说json的话直接可以点出来,像数据的话 data[0]需要给下标才能点出来, java呢处理json就比较复杂了 import org.json.JSON;需要导一下包,对于已经toString的字符串可以使用JSONObject obj = new JSONObject(str);进行转换成json这样obj就可以 obj.get("key")的形式获取json二级数据像对于有数组的JSON使用的方式是obj.getjsonArray并且接收值也需要JSONARRAY来接收 这样的话可以 obj.get(index)来获取JSONObject的数据总的来说呢,java处理JSON数据相对于PHP和js来说比较复杂 来源: https://www.cnblogs.com/Thehorse/p/11601066.html

HttpClient 使用案例

亡梦爱人 提交于 2019-11-30 14:32:04
package com.qifeng.config.ygx.common.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import lombok.SneakyThrows; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.ParseException; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpUriRequest; import org.apache