使用xml sharepreference等存放json信息并读取
2012-11-26 10:47
225 查看
最近项目中有些人使用xml存储了一些区域级联信息 (类型于山东 -(济南市,青岛市(崂山,四方)))这样的信息.使用 的是吧xml数据存储到sharepreference 感觉不是很好,费力不讨好
于是想到了json
确实,有些东西不必用到数据库 使用json和xml就可以了.个人偏好json
string.xml中储存的信息
韩老师说,速度上数据库小于文件,我想这指的是小数据把?大数据还是要用数据库的
于是想到了json
确实,有些东西不必用到数据库 使用json和xml就可以了.个人偏好json
package com.example.testjsonandxml; import org.json.JSONException; import org.json.JSONObject; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.widget.TextView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String json = getString(R.string.json); DataStoreUtil.put(this, "json", json); JSONObject jsonObject; try { jsonObject = new JSONObject(json); TextView textView = new TextView(this); textView.setText(jsonObject.getString("name")); textView.append(jsonObject.getString("price")); textView.append("来自SharePreference:"+new JSONObject(DataStoreUtil.getString( MainActivity.this, "json")).getString("mktprice")); setContentView(textView); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
string.xml中储存的信息
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">TestJsonAndXml</string> <string name="hello_world">Hello world!</string> <string name="menu_settings">Settings</string> <string name="json">{"goods_id":"1002109","name":"\u7f8e\u53a8\u667a\u5229\u94f6\u9cd5500g","price":"158.000","mktprice":"189.600"}</string> </resources>
韩老师说,速度上数据库小于文件,我想这指的是小数据把?大数据还是要用数据库的
相关文章推荐
- 使用xml sharepreference等存放json信息并读取
- C/C++使用libcurl库发送http请求(get和post可以用于请求html信息,也可以请求xml和json等串)
- 使用XmlTextReader类从字符串中读取XML节点信息.
- 从数据库读取数据存放在List<T>中,在jsp中将其取出来。(使用JSON)
- 使用Spring中Src下 -context.xml : 用资源文件夹保存数据库的链接信息 并在配置文件里读取
- Flex使用HttpService读取XML信息
- 使用 ApplicationInfo 读取 AndroidManifest.xml 中的meta-data信息
- AJAX XML 实例 下面的例子将演示网页如何使用 AJAX 来读取来自 XML 文件的信息:
- 使用Spring读取xml文件中的配置信息
- 【XML配置文件读取】使用jdom读取XML配置文件信息
- 使用JDOM读取XML信息
- Android——使用Volley+fastJson在新线程中读取网络接口获取天气信息
- C/C++使用libcurl库发送http请求(get和post可以用于请求html信息,也可以请求xml和json等串)
- 使用JDOM读取XML信息
- unity使用Newtonsoft.json反序列化json ,读取你想要的信息
- 在.NET中使用Newtonsoft.Json转换,读取,写入
- 在JSP开发中使用jdom解析临时存放数据的XML文件
- 使用XmlDocument将dropdownlist中显示的书名的其它信息读入到相应的文本框中
- 在asp.net中读取xml文件信息的4种方法