解析通过Android对象

问题描述:

我如何正确地将这些值存储到我的android代码中?解析通过Android对象

{ 
    "propoints": "25", 
    "preflocation": "Adele H. Stamp Student Union" 
    } 

我的PHP创建这样

$响应=阵列的阵列( “棒点”=> “”, “preflocation”=> “”);

商店使用json_encode

我不知道如何来存储hashs返回,并存储到我的变量

JSONArray feedArr = new JSONArray(ActionEngine.jsonParser.getJSONString()); 

      ProcityActivity.propoints = (String) feedArr.get(0); 
      ProcityActivity.preflocation = (String) feedArr.get(1); 

      Toast.makeText(act.getApplicationContext(), 
        ActionEngine.jsonParser.getJSONString(), Toast.LENGTH_SHORT) 
        .show(); 
+0

你是什么意思“有些麻烦”? – MariusBudin

+0

我不知道如何正确取回json_encode哈希值并将其值存储到我的变量中。 – David

有对JSONObject的构造函数(如一个你有作为的价值和回报例如),作为参数从互联网上的数据(流或字符串),然后你可以将它与Gson直接映射到你的对象

(更多关于:http://en.wikipedia.org/wiki/GSON

,或者您可以使用的方法绘制出值的描述:http://developer.android.com/reference/org/json/JSONObject.html

首先,在开始的JSON片段是不是一个JSONArray而是一个JSONObject。其次,通过静态变量存储值并不是最好的想法。第三,这个吐司表示你在保存java片段的对象中存储了一些活动实例。传递一个上下文。