6.10
所花时间(包括上课):2.5
打码量(行):300
博客量(篇):1
了解到知识点:学习JSON
package com.example.myapp;
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 示例代码:解析 JSON 字符串
String jsonString = "{\"name\": \"John\", \"age\": 30, \"city\": \"New York\"}";
try {
JSONObject jsonObject = new JSONObject(jsonString);
String name = jsonObject.getString("name");
int age = jsonObject.getInt("age");
String city = jsonObject.getString("city");
Log.d(TAG, "Name: " + name);
Log.d(TAG, "Age: " + age);
Log.d(TAG, "City: " + city);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
本文来自博客园,作者:赵千万,转载请注明原文链接:https://www.cnblogs.com/zhaoqianwan/p/18209297
千万千万赵千万