小编l-l*_*l-l的帖子

将JSON数据放入List中

我从我的服务器正确地获取了JSON数据,我只想将它放入以下数组中,但我不确定JSON数据是否正确插入到ArrayList中.

这是阵列

private List<ShopInfo> createList(int size)  {
    List<ShopInfo> result = new ArrayList<ShopInfo>();
    for (int i = 1; i <= size; i++) {
        ShopInfo ci = new ShopInfo();
        ci.name =    TAG_NAME+i;
        ci.address = TAG_ADDRESS+i;
        result.add(ci);
    }
    return result;
}
Run Code Online (Sandbox Code Playgroud)

我的json

{"success":1,"shops":[{"name":"Test_Shop","address":"1 Big Road Dublin"}
Run Code Online (Sandbox Code Playgroud)

文件

public class OrderCoffee extends Activity {

JSONParser jParser = new JSONParser();
ArrayList<HashMap<String, String>> shopList;
private static String url_all_products = "xxxxxxxxxx/ordercoffee.php";
// products JSONArray
JSONArray shops = null;


// JSON Node names
private static final String TAG_SUCCESS …
Run Code Online (Sandbox Code Playgroud)

java android json android-asynctask

2
推荐指数
1
解决办法
980
查看次数

如果您有歌曲ID,Android会从Media Store获取歌曲吗?

我从MediaStore的播放列表中获得了歌曲ID,使用

long id = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Playlists.Members.AUDIO_ID));
Run Code Online (Sandbox Code Playgroud)

并且ID是正确的,但由于仅有的其他可用数据是CONTENT_DIRECTORY,DEFAULT_SORT_ORDER,PLAYLIST_ID,PLAY_ORDER和_ID,因此我不确定如何获取歌曲的重要部分。我需要标题,专辑,艺术家等,就好像我正在通过MediaStore.Audio.Media获取歌曲信息一样。

我找到了一个尝试修改的答案以满足自己的需求,但是我不太了解查询或游标,因此我不确定是否有获取歌曲的方法。

如果唯一的方法是在每首歌曲中循环播放,直到找到匹配的ID,我就可以做到这一点,但是这样做效率低下,必须有更好的方法。

提前致谢!

java search android cursor mediastore

2
推荐指数
1
解决办法
2679
查看次数

我如何用Java解析这个JSON?

我对此有点新意,它正在努力!我一直收到这个错误:

解析数据时出错org.json.JSONException:tname没有值

这是json:

[{"tname":"2"},{"kword":"||ice+skating+rink"}]
Run Code Online (Sandbox Code Playgroud)

这是我的java代码:

String result = response.toString();

            try
            {
                JSONArray jArray = new JSONArray(result);

                for (int i = 0; i < jArray.length(); i++) {
                    JSONObject json_data = jArray.getJSONObject(i);
                    Log.i("log_tag", ", type: " + json_data.getString("tname")+
                            ", keyword: " + json_data.getString("kword"));

                    type += json_data.getString("tname");
                    keyword += json_data.getString("kword");
                }
Run Code Online (Sandbox Code Playgroud)

任何帮助非常感谢.

java arrays parsing android json

1
推荐指数
1
解决办法
95
查看次数

Android传递Context到处都是

我开发了一个Android应用程序(对我来说)它太丑了,我很确定我的方法是非常错误的.

我有一堆片段活动和很多类,如异步任务,业务规则等.特别是,我有一个名为PropertiesReader的类,我用它来读取属性文件.我在很多地方使用这个类,比如片段和业务规则.

public class PropertyReader {

    private Properties properties;

    public PropertyReader(Context context){
        super();
        try {
            properties = new Properties();
            properties.load(context.getResources().getAssets().open("badass.properties"));
        } catch (IOException e){
            Log.e("Error", "Error opening properties file", e);
        }
    }

    public String getValue(String key){
        return properties.getProperty(key);
    }
}
Run Code Online (Sandbox Code Playgroud)

在我使用这个课程的每个地方,我做的事情如下:

 PropertyReader bla = new PropertyReader(this); //or new PropertyReader(context);
Run Code Online (Sandbox Code Playgroud)

我想知道什么是使用需要构造Context的类的最佳方法.在我看来,每个构造函数都有一个Context参数非常难看.

有任何想法吗?

预先感谢.

java android android-context

1
推荐指数
1
解决办法
497
查看次数

无法重新提交应用内购买以供审核

我的应用内购买被拒绝了解释:

Your in-app purchase has been returned. 
Fix the marked items and submit it again. 
For more information, see the Notes from App Review.
Run Code Online (Sandbox Code Playgroud)

并在说明中说:

We have returned your in-app purchase products to you as the required
binary was not submitted. When you are ready to submit the binary,     
please resubmit the in-app purchase products with the binary.
Run Code Online (Sandbox Code Playgroud)

不知道这意味着什么,但我已经提交了一个新的二进制文件.尽管如此,当二进制文件处于"等待审核"时,应用程序内购买的状态仍然是"需要开发者操作".

但是,没有任何"提交"按钮用于应用内购买.接下来我该怎么办?

谢谢.

itunesconnect in-app-purchase ios

1
推荐指数
1
解决办法
983
查看次数