我需要一些帮助.我还是Android开发人员的新手.
这是数据的示例
strAPI_TERMINAL= "{ 'terminal': { 'id': 2, 'fmt_id': 'fmt0002', 'terminal_type': 'multiple' }}"
Run Code Online (Sandbox Code Playgroud)
我需要将此对象数据解析为JSONArray
在这里我做了什么......
JSONObject jsonObject = new JSONObject(strAPI_TERMINAL);
JSONArray terminal_array = new JSONArray();
JSONArray t_array = terminal_array.put(jsonObject);
Run Code Online (Sandbox Code Playgroud)
当我注销数据时...是的,就像这样解析数组
t_array[{"terminal":{"fmt_id":"fmt0002","id":2,"terminal_type":"multiple"}]
但当我想使用它来获取"终端"数据时...
JSONArray TERMINAL_JSON=new JSONArray(t_array.getJSONObject(i).getString("terminal").toString());
Run Code Online (Sandbox Code Playgroud)
它说:
Error:Value {"id":2,"fmt_id":"fmt0002","terminal_type":"multiple"}
Run Code Online (Sandbox Code Playgroud)
有人请帮帮我???
谢谢你的帮助...
我真的需要你帮助这个代码,我使用loopj.com/android-async-http与服务器通信,一切正常但一直试图循环我从服务器获得的json对象.
{ "行":[{ "FNAME": "的Eb \'希姆", "L-NAME": "Durosimi", "预测": "4", "Cpredictions": "3", "点": "15"} ,{ "FNAME": "Otunba", "L-NAME": "Alagbe", "预测": "5", "Cpredictions": "2", "点": "10"},{ "FNAME":"奥拉米德" "L-NAME": "Jolaoso", "预测": "4", "Cpredictions": "2", "点": "10"},{ "FNAME": "G", "L-NAME":" ADE " "预测": "1", "Cpredictions": "1", "点": "5"},{ "FNAME": "Tiamiyu", "L-NAME": "waliu", "预测":" 1 ", "Cpredictions": "1", "点": "5"}]}
但是还没有能够把它弄好,尝试了不同的例子,但无济于事.
public void onSuccess(String content) {
// TODO Auto-generated method stub
super.onSuccess(content);
try {
JSONObject json = new JSONObject(content);
JSONObject leaders= json.getJSONObject("rows");
Log.d("leaders",leaders.toString());
for(int …Run Code Online (Sandbox Code Playgroud) 我有字符串对象:
String qwe =
"{\"myObj\":"
+ "{"
+ "\"first\":123,"
+ "\"second\":111.0}"
+"}";
我的代码
private static final String TAG_FIRST = "first";
res = new JSONObject(qwe);
Double q1 = res.getDouble(TAG_FIRST);
Run Code Online (Sandbox Code Playgroud)
我有"先没有价值"的例外.
我做错了什么?
抱歉我的英语不好.最好的祝福
我想将json数据转换为字符串
import java.io.BufferedReader;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import org.json.JSONArray;
import org.json.JSONObject;
public static void main(String[] args) throws Exception
{
URL url = new URL("http://192.168.1.13/test/ProductWb.php?productId=9");
HttpURLConnection conn ;
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setReadTimeout(60);
conn.setRequestProperty("Accept", "application/json");
String json="";
json = readUrl(conn);
System.out.println(json);
JSONObject jsonObject=new JSONObject(json);
JSONArray jarray=jsonObject.getJSONArray("modeles");
JSONObject modele= jarray.getJSONObject("modele");
for (int i=0;i<modele.length();i++) {
System.out.println(modele(i).getString("id_product"));
System.out.println(modele(i).getString("meta_title"));
System.out.println("*********");
}
}
Run Code Online (Sandbox Code Playgroud)
它告诉我json数据,但给我这个错误:
{"modeles":[{"modele":{"id_product":"9","id_shop":"1","id_lang":"4","description":null,"description_short":"<pre>Peugeot 208<\/pre>","info_prix":"","info_1":null,"info_2":null,"info_3":null,"info_4":null,"info_5":null,"link_rewrite":"208","meta_description":"Peugeot 208","meta_keywords":"peugeot 208","meta_title":"Peugeot 208","name":"208","available_now":"","available_later":""}}]}
Exception in thread "main" java.lang.IllegalStateException: This is not a JSON Array.
at …Run Code Online (Sandbox Code Playgroud) 我正在尝试0s从a 开始获取数值JSONObject.问题是该方法将字符串转换为double.例:
的JSONObject:
{
"LATITUDE1":41,
"LATITUDE2":06962
}
Run Code Online (Sandbox Code Playgroud)
我用的时候
String lat2 = object.getString("LATITUDE2");
Run Code Online (Sandbox Code Playgroud)
字符串lat2显示为6962.0.我怎样才能使字符串显示在json文件中(如06962)?
然后我需要连接两个值并在它们之间添加一个点以获得十进制数,41.06962这就是为什么我需要将值作为字符串获取.
谢谢
成功登录会JSONObject从服务器返回以下内容:
{"success":true,"message":"Sign in success.","response_data":{"user_id":"24", "email_id":"user@gmail.com", "secret_code": "You did it!"}}
Run Code Online (Sandbox Code Playgroud)
我想把response_data信息放到我的User对象中.我以前做过这样的事情:
String getResponse = jsonObject.getString("response_data");
Gson gson = new GsonBuilder()
.disableHtmlEscaping()
.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
.setPrettyPrinting()
.serializeNulls()
.create();
//All the data in the `response_data` is initialized in `User`
User user = gson.fromJson(getResponse, User.class);
Run Code Online (Sandbox Code Playgroud)
现在我尝试在改造中做同样的事情:
初始化RestAdapter +接口:
public class ApiClient {
private static RetrofitService sRetrofitService;
public static RetrofitService getRetrofitApiClient() {
if (sRetrofitService == null) {
RestAdapter restAdapter = new RestAdapter.Builder()
.setLogLevel(RestAdapter.LogLevel.FULL)
.setEndpoint("http://xxx.xxx.xxx.xxx/")
.build();
sRetrofitService = restAdapter.create(RetrofitService.class);
}
return sRetrofitService; …Run Code Online (Sandbox Code Playgroud) 如何json object在sdcard中保存文件?