Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检索JSON并在表布局(Android)中显示它_Android_Json_Android Asynctask - Fatal编程技术网

检索JSON并在表布局(Android)中显示它

检索JSON并在表布局(Android)中显示它,android,json,android-asynctask,Android,Json,Android Asynctask,我是Android的新手,作为一个项目的一部分,我需要访问一个网站,在那里检索JSON信息,然后显示它。它必须使用AsyncTask异步完成。我在某种程度上理解了检索数据的想法,但如何处理JSON对象本身,以及如何将对象的某些元素放入显示的某些区域,我使用了带有TextView的表布局,虽然我知道listview会更好,但我希望它能以这种方式工作,然后继续前进 这是JSON在网页上的外观: {"shopLocation":"web","shopName":"ABC", "item

我是Android的新手,作为一个项目的一部分,我需要访问一个网站,在那里检索JSON信息,然后显示它。它必须使用AsyncTask异步完成。我在某种程度上理解了检索数据的想法,但如何处理JSON对象本身,以及如何将对象的某些元素放入显示的某些区域,我使用了带有TextView的表布局,虽然我知道listview会更好,但我希望它能以这种方式工作,然后继续前进

这是JSON在网页上的外观:

    {"shopLocation":"web","shopName":"ABC",
    "items":[{"id":1,"item":"Item1","price":"23.90"},
    {"id":2,"item":"Item2","price":"18.36"},
    {"id":3,"item":"Item3","price":"53.90"}]}
这是布局图

           <Table Layout android:layout_width="match_parent"
        android:layout_height="wrap_content">
    <TableRow android:layout_height="wrap_content"
              android:layout_width="wrap_content">
        <TextView android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Location:"/>
        <TextView android:layout_height="wrap_content"
                  android:layout_width="wrap_content"
                  android:id="@+id/shopLocationText"
                  android:layout_weight="1"/>
    </TableRow>
    <TableRow android:layout_height="wrap_content"
              android:layout_width="wrap_content">
        <TextView android:layout_height="wrap_content"
                  android:layout_width="wrap_content"
                  android:text="Shop Name:"/>
        <TextView android:layout_height="wrap_content"
                  android:layout_width="wrap_content"
                  android:id="@+id/shopNameText"
                  android:layout_weight="1"/>
    </TableRow>        
    <TableRow android:layout_height="wrap_content"
              android:layout_width="wrap_content">
        <TextView android:layout_height="wrap_content"
                android:layout_width="0px"
                android:textSize="25dp"
                android:layout_weight="1"/>
        <TextView android:layout_height="wrap_content"
                  android:layout_width="0px"
                  android:text="Item:"
                  android:textSize="25dp"
                android:layout_weight="1"/>
        <TextView android:layout_height="wrap_content"
                  android:layout_width="0px"
                  android:text="Price"
                android:layout_weight="1"/>
    </TableRow>
    <TableRow android:layout_height="wrap_content"
              android:layout_width="wrap_content">
        <TextView android:layout_height="wrap_content"
                  android:layout_width="0px"
                  android:id="@+id/ID1Text"
                  android:layout_weight="1"/>
        <TextView android:layout_height="wrap_content"
                  android:layout_width="0px"
                  android:id="@+id/item1Text"
                  android:layout_weight="1"/>
        <TextView android:layout_height="wrap_content"
                  android:layout_width="0px"
                  android:id="@+id/price1Text"
                  android:layout_weight="1"/>
      </TableRow>
</TableLayout>
如何从url中检索JSON数据我不希望使用AsyncTask专门发布实际的url,然后在这样做之后,如何分解数据并将其连接到它的文本视图?我切断了一些布局xml文件


我真的处于困境,任何和所有的帮助都将是绝对伟大的

关于如何解析json并在listview或表中显示它,google上有很多教程。如果你是一个新手,那么你应该阅读教程。我已经阅读并看过很多教程,但我无法制作一个功能性应用程序,它们总是会崩溃,你可以在LOGCAT中找到原因。请先阅读基本的android教程