简体   繁体   English

从类中解析JSON。 Android的

[英]Parse JSON from class. Android

There is a code with JSON. 有一个带有JSON的代码。 I am beginner and I do not understand this code. 我是初学者,我不理解此代码。

Can anybody explain what I have? 谁能解释我的财产?

And ways to make code as a working app. 以及使代码成为可正常运行的应用程序的方法。

public class G_JSON_Activity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_j__json_);

    final String json = "{  \n" +
            "\t\"id\": 9999,  \n" +
            "\t\"firstName\": \"Joe\",  \n" +
            "\t\"lastName\": \"Richard\"\n" +
            "}";
}

There are comments: 有评论:

// (Button)bParse: parse 
// Set textview text from JSON: [firstname]+[ ]+[lastname]'s id is [id]
  • You are subclassing actionbaractivity it gives actionbar functionality to the activity, some additional methods and properties that are not available to general activity.such as making tabs etc.. 您正在将actionbaractivity子类化,它为活动提供了actionbar功能,一些常规活动不可用的其他方法和属性,例如制作选项卡等。

  • super.onCreate(savedInstanceState); you tell the Dalvik VM to run your code in addition to the existing code in the onCreate() of the parent class. 您可以告诉Dalvik VM除了运行父类的onCreate()中的现有代码外,还可以运行您的代码。

  • You are setting activity_j__json_ layout in contentview which means the xml ui will be shown in the actionbaraactivity 您正在contentview中设置activity_j__json_布局,这意味着xml ui将显示在actionbaraactivity中

  • then an constant string json variable is declared and assigned an json value. 然后声明一个常量字符串json变量,并为其分配一个json值。

You can still run the project if there is no compilation error in your project due to other project files such as activity_j__json_ 如果由于其他项目文件(例如activity_j__json_)而导致您的项目中没有编译错误,您仍然可以运行该项目

-- Update: -更新:

I think you would have textview in the activity_j_json see if you have anything like this in it and not the id 我想你会在activity_j_json中有textview看看是否有这样的东西而不是id

 <TextView
    android:id="@+id/myTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:textSize="20sp" />

In the source code 在源代码中

    TextView mTextView = (TextView)findViewById(R.id.myTextView);

    mTextView.setText(json);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM