【问题标题】:How to get Images from JSON to main.xml file如何从 JSON 获取图像到 main.xml 文件
【发布时间】:2012-02-21 07:38:45
【问题描述】:

我没有从 JSON 中获取图像。

如何从我的 JSON 中获取“LogoFileName”图像。我只得到标题和描述。但我也需要 LogoFileName。 如果有人知道任何解决方案,请帮助我。

代码:

{"Channels":[{"AlertDetailsFont":"","AlertDetailsFontId":0,"AlertHeaderFont":"","AlertHeaderFontId":0,"Category":"Education","CategoryId":7,"ChannelId":53,"Color1":"Red","Color2":"Black","Color3":"Black","Color4":"","Color5":"","ColorCode1":"FF0000","ColorCode2":"000000","ColorCode3":"000000","ColorCode4":"","ColorCode5":"","ColorId1":1,"ColorId2":3,"ColorId3":3,"ColorId4":0,"ColorId5":0,"Description":"This must be visible now","FontSize":"12px","FontSizeId":1,"HeaderFont":"Arial","HeaderFontId":2,"IsBold":false,"IsItalic":false,"LogoFileName":"http:\/\/183.82.97.146:1111\/CAWebsite\/UserImages\/ChannelLogos\/02022012_170628.jpg","ModifiedBy":12,"ModifiedDate":"\/Date(1328182588000+0530)\/","ModifiedUsername":"skrt","PublicChannelId":"f12d79aa-4267-11e1-a94b-0021706baaba","TickerFont":"","TickerFontId":0,"Title":"Books"},,.................etc

您好,这是我的代码..

main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"

    android:padding="6dip">

    <ImageView
        android:id="@+id/icon"

        android:layout_width="wrap_content"
        android:layout_height="fill_parent"

        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_marginRight="6dip"

        android:src="@drawable/icon" />

    <TextView
        android:id="@+id/item_title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/icon"
        android:layout_alignWithParentIfMissing="true"
        android:layout_toRightOf="@+id/icon"
        android:gravity="center_vertical"
        android:text="My Application" />


    <TextView
        android:id="@+id/item_subtitle"
        android:layout_width="fill_parent"
        android:layout_height="26dip"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@+id/icon"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:text="Simple application that shows how to use RelativeLayout" />
</RelativeLayout>

MainActivity.java

    ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();

    JSONObject json = JSONfunctions.getJSONfromURL("http://my path...");


   try{

        JSONArray  channels = json.getJSONArray("Channels");

        for(int i=0;i<channels.length();i++){                       
        HashMap<String, String> map = new HashMap<String, String> ();   
        JSONObject e = channels.getJSONObject(i);

        map.put("id",  String.valueOf(i));
            map.put("name", e.getString("Title"));
            map.put("Category", e.getString("Category"));
            //map.put("imageUrl", e.getString("LogoFileName"));

            imageUrl= e.getString("LogoFileName");

            System.out.println("Logo Url:"+imageUrl);

            mylist.add(map);            
        }       
               }catch(JSONException e)        
              {
         Log.e("log_tag", "Error parsing data "+e.toString());
              }

    ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.main, 
                    new String[] { "name", "Category" }, 
                    new int[] { R.id.item_title, R.id.item_subtitle });

    setListAdapter(adapter);

    final ListView lv = getListView();
    lv.setTextFilterEnabled(true);

【问题讨论】:

    标签: android json list


    【解决方案1】:

    让我猜猜:你看不到System.out.println("Logo Url:"+imageUrl) 的输出,对吧?请改用Log。还是我误会了?

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-20
    • 2012-01-02
    • 2018-04-25
    • 2018-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多