json影视解析客户端源码(免费影视json解析接口)
本篇文章给大家谈谈json影视解析客户端源码,以及免费影视json解析接口对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
android 在服务器端生成json格式数据,在客户端怎么解析
因为这次要从服务器端得到Json数据,并且通过解析之后把解析后的数据显示在Android客户端中,首先部署服务器端代码(直接使用Jsp/Servlet):
构造的Json数据如下:
[{"name":"张三","address":"北京","age":20},{"name":"李四","address":"上海","age":30},{"name":"王五","address":"深圳","age":35}]
[一]服务器端(Person.java省略):
①:数据构造JsonService.java
public class JsonService {
public static ListPerson getListPerson() {
ListPerson mLists = new ArrayListPerson();
mLists.add(new Person("张三", "北京", 20));
mLists.add(new Person("李四", "上海", 30));
mLists.add(new Person("王五", "深圳", 35));
return mLists;
}
②:Servlet的代码(包括构造Json数据,没有使用Json数据转换方法)JsonServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
ListPerson persons = JsonService.getListPerson();
StringBuffer sb = new StringBuffer();
sb.append('[');
for (Person person : persons) {
sb.append('{').append("\"name\":").append("\""+person.getName()+"\"").append(","); sb.append("\"address\":").append("\""+person.getAddress()+"\"").append(",");
sb.append("\"age\":").append(person.getAge());
sb.append('}').append(",");
}
sb.deleteCharAt(sb.length() - 1);
sb.append(']');
out.write(new String(sb));
out.flush();
out.close();
}
③:部署到Tomact 浏览器输入直接访问结果如下:
[{"name":"张三","address":"北京","age":20},{"name":"李四","address":"上海","age":30},{"name":"王五","address":"深圳","age":35}]
至此服务器端代码编码完成,下面进行客户端代码编写; (二)客户端(Person类,和展示数据的布局文件因为简单省去) ①:获取服务器端的Json数据并且解析的工具类JsonParse.java 必要的需要导入的包省去
public class JsonParse {
/**
* 解析Json数据
*
* @param urlPath
* @return mlists
* @throws Exception
*/
public static ListPerson getListPerson(String urlPath) throws Exception {
ListPerson mlists = new ArrayListPerson();
byte[] data = readParse(urlPath);
JSONArray array = new JSONArray(new String(data));
for (int i = 0; i array.length(); i++) {
JSONObject item = array.getJSONObject(i);
String name = item.getString("name");
String address = item.getString("address");
int age = item.getInt("age");
mlists.add(new Person(name, address, age));
}
return mlists;
}
/**
* 从指定的url中获取字节数组
*
* @param urlPath
* @return 字节数组
* @throws Exception
*/
public static byte[] readParse(String urlPath) throws Exception {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] data = new byte[1024];
int len = 0;
URL url = new URL(urlPath);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
InputStream inStream = conn.getInputStream();
while ((len = inStream.read(data)) != -1) {
outStream.write(data, 0, len);
}
inStream.close();
return outStream.toByteArray();
}
}
②:主Activity类
public class MainActivity extends Activity {
private Button mButton;
private ListView mListView;
//使用IP不能使用localhost或者127.0.0.1,因为android模拟器默认绑定这个IP,这里应该访问局域网IP
private static final String urlPath = "";
private static final String TAG = "MainActivity";
private ListPerson persons;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mButton = (Button) findViewById(R.id.button1);
mListView = (ListView) findViewById(R.id.listView1);
mButton.setOnClickListener(new MyOnClickListener());
}
private class MyOnClickListener implements OnClickListener {
@Override
public void onClick(View v) {
try {
// 得到Json解析成功之后数据
persons = JsonParse.getListPerson(urlPath);
ListHashMapString, Object data = new ArrayListHashMapString, Object();
for (int i = 0; i persons.size(); i++) {
HashMapString, Object map = new HashMapString, Object();
map.put("name", persons.get(i).getName());
map.put("address", persons.get(i).getAddress());
map.put("age", persons.get(i).getAge());
data.add(map);
}
//初始化适配器,并且绑定数据
SimpleAdapter _Adapter = new SimpleAdapter(MainActivity.this,
data, R.layout.listview_item, new String[] { "name",
"address", "age" }, new int[] { R.id.textView1,
R.id.textView2, R.id.textView3 });
mListView.setAdapter(_Adapter);
} catch (Exception e) {
Toast.makeText(MainActivity.this, "解析失败", 2000).show();
Log.i(TAG, e.toString());
}
}
}
js 解析json数据填充到html里,求源码~~
ul
li id="li"数据填充到这里就行了/li
/ul
var nearInfo=[{"retmsg": "success",”id“:100,"name": "中山公园"},
{"retmsg": "success",”id“:100,"name": "中山公园"}];
// json转对象
var result = $.parseJSON(nearInfo);
for(var i=0;iresult.length;i++){
$('#li').html(result[i].name);
}
这里只填了个name , 你看懂了,其他就好说了
json影视接口怎么写
json影视接口怎么写
JSON影视接口一般是指用JSON数据格式返回的影视信息的接口,其具体实现可以分为以下几个步骤:
1. 确定数据格式:首先需要确定JSON影视接口返回的数据格式,包括影视信息的字段,以及每个字段的类型等;
2. 构建接口:构建影视接口,包括定义接口的路径,接口参数,以及接口返回的数据格式等;
3. 实现接口:根据接口定义,实现接口,从数据库中获取影视信息,并将信息以JSON格式返回给客户端;
4. 测试接口:使用测试工具测试接口的功能,确保接口的正确性和可靠性;
5. 部署接口:将接口部署到服务器上,供客户端调用。
json影视解析客户端源码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于免费影视json解析接口、json影视解析客户端源码的信息别忘了在本站进行查找喔。