JSON数据不会加载到我的Android应用程序中(JSON data wont load into my android app)

我需要一些关于操作JSON数据的建议。 我得出一个绝对的结论,即我在博客中使用的JSON数据有问题。

我将JSON数据提供给Android应用程序以显示应用程序的信息。 我遇到的问题是,当我使用我的JSON数据时,我得到一个negativearraysize异常。

在你责备代码之前,知道我使用teamtreehouse博客JSON代码在这里工作,使应用程序正常工作:

http://blog.teamtreehouse.com/api/get_recent_summary/

所以这很好。 我使我的JSON代码看起来几乎与此代码完全一样。 嵌套相同的数组,使用相同的命名约定......等等。

这是我的JSONcode,当它插入我的Android代码时会带回异常。

http://www.evotechmachine.com/api/get_recent_posts/?include=title,url,status,id,date

如果你比较两个JSON代码,你会发现它们内部几乎相同。 我唯一引用的是帖子,标题和网址。 我敢肯定它不是名字不匹配。 我完全失去了。 在此先感谢人们。

public static final int NUMBER_OF_POSTS = 20;
public static final String TAG = MainListActivity.class.getSimpleName();
protected JSONObject mBlogData;
protected ProgressBar mProgressBar;
private final String KEY_TITLE = "title";
private final String KEY_AUTHOR = "author";
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_list);

    mProgressBar = (ProgressBar) findViewById(R.id.progressBar1);


    if (isNetworkAvailable()) {
    mProgressBar.setVisibility(View.VISIBLE);
        GetBlogPostsTask getBlogPostsTask = new GetBlogPostsTask();
    getBlogPostsTask.execute();
    }
    else {Toast.makeText(this, "network is unavailable", Toast.LENGTH_LONG).show();

    }
    // Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        JSONArray jsonPosts;
        try {
            jsonPosts = mBlogData.getJSONArray("posts");            
            JSONObject jsonPost = jsonPosts.getJSONObject(position);
            String  blogUrl = jsonPost.getString("url");
            Intent intent = new Intent(this, BlogWebViewActivity.class);
            intent.setData(Uri.parse(blogUrl));
            startActivity(intent);
        } catch (JSONException e) {
            logException(e);
        }

}
private void logException(Exception e) {
    Log.e(TAG, "Exception caught!", e);
}

private boolean isNetworkAvailable() {
    ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo networkInfo = manager.getActiveNetworkInfo();

    boolean isAvailable = false;
    if (networkInfo != null && networkInfo.isConnected()) {
        isAvailable = true;
    }
    return isAvailable;
    }


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
public void handleBlogResponse() {
    mProgressBar.setVisibility(View.INVISIBLE);
    if(mBlogData==null) {
        updateDisplayForError();
    }
    else {
        try {
         JSONArray jsonPosts = mBlogData.getJSONArray("posts");
        ArrayList<HashMap<String, String>> blogPosts = 
                new ArrayList<HashMap<String, String>>();

         for (int i = 0;i< jsonPosts.length();i++) {
             JSONObject post = jsonPosts.getJSONObject(i);
             String title = post.getString(KEY_TITLE);
             title = Html.fromHtml(title).toString();
             String author = post.getString(KEY_AUTHOR);
             author = Html.fromHtml(author).toString();         

             HashMap<String, String> blogPost = new HashMap<String, String>();
             blogPost.put(KEY_TITLE, title);
             blogPost.put(KEY_AUTHOR, author);

             blogPosts.add(blogPost);

         }

         String[] keys= { KEY_TITLE, KEY_AUTHOR };
         int[] ids = {android.R.id.text1, android.R.id.text2};
         SimpleAdapter adapter = new SimpleAdapter(this, blogPosts, android.R.layout.simple_list_item_2, keys, ids);
         setListAdapter(adapter);
        } catch (JSONException e) {
            logException(e);
        }
    }

}


private void updateDisplayForError() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.error_title));
    builder.setMessage(getString(R.string.error_message));

    builder.setPositiveButton(android.R.string.ok, null);
    AlertDialog dialog = builder.create();
    dialog.show();

    TextView emptyTextView = (TextView) getListView().getEmptyView();
    emptyTextView.setText(getString(R.string.no_items));
}    
private class GetBlogPostsTask extends AsyncTask<Object, Void, JSONObject> {

    @Override
    protected JSONObject doInBackground(Object... arg0) {
        int responseCode = -1;
        JSONObject jsonResponse = null;
        try {
            URL blogFeedUrl = new URL("http://www.evotechmachine.com/api/get_recent_posts/?include=title,url,status,id,date");
            HttpURLConnection connection = (HttpURLConnection) blogFeedUrl.openConnection();
            connection.connect();

            responseCode = connection.getResponseCode();
            if (responseCode == HttpURLConnection.HTTP_OK){
                InputStream inputStream = connection.getInputStream();
                Reader reader = new InputStreamReader(inputStream);
                int contentLength = connection.getContentLength();
                char[] charArray = new char[contentLength];
                reader.read(charArray);
                String responseData = new String(charArray);

                jsonResponse = new JSONObject(responseData);

            } else {
                Log.i(TAG, "unsuccessful HTTP Response Code: " +responseCode);
            }
            Log.i(TAG, "Code: " + responseCode);
        } catch (MalformedURLException e) {

            logException(e);}
    catch (IOException e) {
        logException(e);    
    }
        catch (Exception e) {
            logException(e);
        }        

        return jsonResponse;
    }

    @Override
    protected void onPostExecute(JSONObject result) {
        mBlogData = result;

        handleBlogResponse();
    }
}

}

这是logcat:

07-31 20:49:08.209: E/(32544): <s3dReadConfigFile:75>: Can't open file for reading
07-31 20:49:08.209: E/(32544): <s3dReadConfigFile:75>: Can't open file for reading
07-31 20:49:09.280: E/MainListActivity(32544): Exception caught!
07-31 20:49:09.280: E/MainListActivity(32544): java.lang.NegativeArraySizeException: -1
07-31 20:49:09.280: E/MainListActivity(32544):  at com.nibbdigital.blogreader.MainListActivity$GetBlogPostsTask.doInBackground(MainListActivity.java:168)
07-31 20:49:09.280: E/MainListActivity(32544):  at com.nibbdigital.blogreader.MainListActivity$GetBlogPostsTask.doInBackground(MainListActivity.java:1)
07-31 20:49:09.280: E/MainListActivity(32544):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-31 20:49:09.280: E/MainListActivity(32544):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-31 20:49:09.280: E/MainListActivity(32544):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-31 20:49:09.280: E/MainListActivity(32544):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-31 20:49:09.280: E/MainListActivity(32544):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-31 20:49:09.280: E/MainListActivity(32544):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-31 20:49:09.280: E/MainListActivity(32544):  at java.lang.Thread.run(Thread.java:856)

I need some advice on manipulating JSON data. I've come to an absolute conclusion that there is something wrong with the JSON data that I am using for my blog.

I'm feeding the JSON data into an android application to display information on the app. The problem I am having is that when I use my JSON data I get a negativearraysize exception.

Now before you blame the code, know that I got the app to work fine using the teamtreehouse blog JSON code to work here:

http://blog.teamtreehouse.com/api/get_recent_summary/

SO this works fine. I made my JSON code look almost exactly like this code. The arrays a nested the same, same naming conventions are used... etc..

Here is my JSONcode that brings back the exception when its plugged in to my android code.

http://www.evotechmachine.com/api/get_recent_posts/?include=title,url,status,id,date

If you compare the two JSON codes you'll see that they are pretty much the same on the inside. The only thing I reference in either is the Posts, title, and url. I'm sure its not a mismatch of names. I'm at a total loss. thanks in advance people.

public static final int NUMBER_OF_POSTS = 20;
public static final String TAG = MainListActivity.class.getSimpleName();
protected JSONObject mBlogData;
protected ProgressBar mProgressBar;
private final String KEY_TITLE = "title";
private final String KEY_AUTHOR = "author";
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_list);

    mProgressBar = (ProgressBar) findViewById(R.id.progressBar1);


    if (isNetworkAvailable()) {
    mProgressBar.setVisibility(View.VISIBLE);
        GetBlogPostsTask getBlogPostsTask = new GetBlogPostsTask();
    getBlogPostsTask.execute();
    }
    else {Toast.makeText(this, "network is unavailable", Toast.LENGTH_LONG).show();

    }
    // Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        JSONArray jsonPosts;
        try {
            jsonPosts = mBlogData.getJSONArray("posts");            
            JSONObject jsonPost = jsonPosts.getJSONObject(position);
            String  blogUrl = jsonPost.getString("url");
            Intent intent = new Intent(this, BlogWebViewActivity.class);
            intent.setData(Uri.parse(blogUrl));
            startActivity(intent);
        } catch (JSONException e) {
            logException(e);
        }

}
private void logException(Exception e) {
    Log.e(TAG, "Exception caught!", e);
}

private boolean isNetworkAvailable() {
    ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo networkInfo = manager.getActiveNetworkInfo();

    boolean isAvailable = false;
    if (networkInfo != null && networkInfo.isConnected()) {
        isAvailable = true;
    }
    return isAvailable;
    }


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
public void handleBlogResponse() {
    mProgressBar.setVisibility(View.INVISIBLE);
    if(mBlogData==null) {
        updateDisplayForError();
    }
    else {
        try {
         JSONArray jsonPosts = mBlogData.getJSONArray("posts");
        ArrayList<HashMap<String, String>> blogPosts = 
                new ArrayList<HashMap<String, String>>();

         for (int i = 0;i< jsonPosts.length();i++) {
             JSONObject post = jsonPosts.getJSONObject(i);
             String title = post.getString(KEY_TITLE);
             title = Html.fromHtml(title).toString();
             String author = post.getString(KEY_AUTHOR);
             author = Html.fromHtml(author).toString();         

             HashMap<String, String> blogPost = new HashMap<String, String>();
             blogPost.put(KEY_TITLE, title);
             blogPost.put(KEY_AUTHOR, author);

             blogPosts.add(blogPost);

         }

         String[] keys= { KEY_TITLE, KEY_AUTHOR };
         int[] ids = {android.R.id.text1, android.R.id.text2};
         SimpleAdapter adapter = new SimpleAdapter(this, blogPosts, android.R.layout.simple_list_item_2, keys, ids);
         setListAdapter(adapter);
        } catch (JSONException e) {
            logException(e);
        }
    }

}


private void updateDisplayForError() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.error_title));
    builder.setMessage(getString(R.string.error_message));

    builder.setPositiveButton(android.R.string.ok, null);
    AlertDialog dialog = builder.create();
    dialog.show();

    TextView emptyTextView = (TextView) getListView().getEmptyView();
    emptyTextView.setText(getString(R.string.no_items));
}    
private class GetBlogPostsTask extends AsyncTask<Object, Void, JSONObject> {

    @Override
    protected JSONObject doInBackground(Object... arg0) {
        int responseCode = -1;
        JSONObject jsonResponse = null;
        try {
            URL blogFeedUrl = new URL("http://www.evotechmachine.com/api/get_recent_posts/?include=title,url,status,id,date");
            HttpURLConnection connection = (HttpURLConnection) blogFeedUrl.openConnection();
            connection.connect();

            responseCode = connection.getResponseCode();
            if (responseCode == HttpURLConnection.HTTP_OK){
                InputStream inputStream = connection.getInputStream();
                Reader reader = new InputStreamReader(inputStream);
                int contentLength = connection.getContentLength();
                char[] charArray = new char[contentLength];
                reader.read(charArray);
                String responseData = new String(charArray);

                jsonResponse = new JSONObject(responseData);

            } else {
                Log.i(TAG, "unsuccessful HTTP Response Code: " +responseCode);
            }
            Log.i(TAG, "Code: " + responseCode);
        } catch (MalformedURLException e) {

            logException(e);}
    catch (IOException e) {
        logException(e);    
    }
        catch (Exception e) {
            logException(e);
        }        

        return jsonResponse;
    }

    @Override
    protected void onPostExecute(JSONObject result) {
        mBlogData = result;

        handleBlogResponse();
    }
}

}

here's the logcat:

07-31 20:49:08.209: E/(32544): <s3dReadConfigFile:75>: Can't open file for reading
07-31 20:49:08.209: E/(32544): <s3dReadConfigFile:75>: Can't open file for reading
07-31 20:49:09.280: E/MainListActivity(32544): Exception caught!
07-31 20:49:09.280: E/MainListActivity(32544): java.lang.NegativeArraySizeException: -1
07-31 20:49:09.280: E/MainListActivity(32544):  at com.nibbdigital.blogreader.MainListActivity$GetBlogPostsTask.doInBackground(MainListActivity.java:168)
07-31 20:49:09.280: E/MainListActivity(32544):  at com.nibbdigital.blogreader.MainListActivity$GetBlogPostsTask.doInBackground(MainListActivity.java:1)
07-31 20:49:09.280: E/MainListActivity(32544):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-31 20:49:09.280: E/MainListActivity(32544):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-31 20:49:09.280: E/MainListActivity(32544):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-31 20:49:09.280: E/MainListActivity(32544):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-31 20:49:09.280: E/MainListActivity(32544):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-31 20:49:09.280: E/MainListActivity(32544):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-31 20:49:09.280: E/MainListActivity(32544):  at java.lang.Thread.run(Thread.java:856)

原文:https://stackoverflow.com/questions/17983762
2021-11-29 22:11

满意答案

您的内容长度为负(即未知)

看看这个有一些见解

https://stackoverflow.com/a/5428670/770467

希望能帮助到你


Your content-length is negative (i.e. unknown)

Check out this for some insights

https://stackoverflow.com/a/5428670/770467

Hope it helps

相关问答

更多

我应该为我的Android应用程序使用SQLite数据库还是只使用JSON?(Should I be using a SQLite db for my Android app or just JSON?)

除非您的数据微不足道,否则使用Sqlite(Android的默认数据库引擎)是结构化数据的推荐存储方法。 JSON对于与服务器交换数据很有用。 Unless your data is trivial, using Sqlite (Android's default DB engine) is the recommended storage approach for structured data. JSON is useful for exchanging data with a server.

如何使用LazyAdapter将JSON加载到ListView中(How to use LazyAdapter to load JSON into ListView)

我想到了! 我将发布我的答案,让其他人从中受益。 好的,我对LazyAdapter进行了一些更改。 这是新的LazyAdapter文件: public class LazyAdapter extends BaseAdapter { private Activity activity; private JSONArray data; private static LayoutInflater inflater = null; public ImageLoader i...

如何将我的应用程序从Eclipse加载到我的Android手机而不是AVD(How to load my app from Eclipse to my Android phone instead of AVD)

首先,您需要在手机上启用USB调试,然后通过USB将其连接到计算机。 那么eclipse应该自动开始调试你的手机而不是AVD。 First you need to enable USB debugging on your phone, then connect it to your computer via USB. Then eclipse should automatically start debugging on your phone instead of the AVD.

何时保存列表数据并在Android应用程序中重新加载数据(When to save list data and re-load data in android app)

正如您可能已经知道的那样, onCreate将在Activity被实例化时调用,因此所有初始化,包括使用从文件或共享首选项加载的列表数据填充Activity。 在何时保存列表数据方面,它完全取决于您希望如何修改数据,因为只有在数据从原始状态更改时才需要保存数据。 当然,您也可以在每次调用onResume时加载数据,并在调用onPause时再次保存数据,以确保在多个应用程序修改相同列表数据时同步数据。 保存列表数据有许多不同的方法。 我建议使用SharedPrefernce,因为它可以为您节省一些麻...

如何从网络动态地将数据加载到我的应用程序中?(How can i dynamically load data into my app from the web?)

您可能需要省略“免费”概念,因为您的要求不是直接的,所以您需要, 数据库 - (为了保存您的数据并检索) Web应用程序 - 创建API以便在请求后发送数据 Web服务器 - 为了托管您的Web应用程序 Android应用程序 - 为了调用API并获取数据。 由于这是一个单词的限制,作为替代,您可以使用GCM 数据库 - - (为了保存您的数据和检索) 在GCM注册的Web应用程序 - 为了注册您的客户端应用程序并发送通知 Web服务器 - 为了托管您的Web应用程序 在GCM注册的Android...

为什么我的原生图书馆不会加载到我的Android应用程序中?(Why won't my native library load in my Android App?)

你可以使用相对路径: System.loadLibrary("mylib") 如果您为armeabi体系结构构建了库(它是默认的库),则路径libs / armeabi /是正确的。 I was able to load them using... System.load("/data/data/com.imtroymiller.myapp/lib/libmylib.so"); It looks like System.load takes the path name and System.lo...

android java manifest.xml不会加载到手机上(android java manifest.xml wont load on phone)

您过早关闭活动代码: <activity android:name="./Splash" > 应该: <activity android:name="./Splash" android:label="@string/app_name" etc.. more attributes and no xml comments like <!-- comments... --> within here > 注意>的不同出现 Eclipse显示那些以...

如何在Android应用程序和本地单元测试中加载相同的JSON文件?(How to load the same JSON file in both an Android app and local unit test?)

如果您使用的是Robolectric,请参阅此答案 。 请注意,“assets”目录是Android概念,它与Java资源不同。 也就是说,您还可以将JSON文件从resources移动到resources ,并在Android和JVM表单中使用它,就像在任何Java应用程序中一样。 If you're using Robolectric, see this answer. Note that the "assets" directory is an Android concept, it's d...

如何让Android应用程序将数据从CSV加载到SQLite一次?(How to make android app load data from CSV to SQLite once?)

您可以使用SharedPreferences来确定您是否已经解析了csv文件。 SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE); Editor editor = sharedpreferences.edit(); editor.putString("someKey", "1"); editor.commit(); 在运行任务之前,您应该通过检查“som...

JSON数据不会加载到我的Android应用程序中(JSON data wont load into my android app)

您的内容长度为负(即未知) 看看这个有一些见解 https://stackoverflow.com/a/5428670/770467 希望能帮助到你 Your content-length is negative (i.e. unknown) Check out this for some insights https://stackoverflow.com/a/5428670/770467 Hope it helps

相关文章

更多

form load 的问题

baseinfoForm.form.load({ url: '/Url/Institution/In ...

开发android App干坏事(一)

最近都是在搞java,android的知识,前两天生日朋友和我聊到,有一个认识的人通过反编译andro ...

《Big Data Glossary》笔记

清明假期翻以前的笔记发现有一些NoSQL相关的内容,比较零散,是之前读《Big Data Glossa ...

自己封装的一个Solr Data Import Request Handler Scheduler

经过将近一天的努力,终于搞定了Solr的Data Import Request HandlerSche ...

android APP 中微信分享功能实现 的总结

//花了很长时间最终完成了微信分享功能,中间走了很多弯路,在此做一下小结,希望对在应用中使用到微信分享 ...

android APP 中微信分享功能实现 的总结

//花了很长时间最终完成了微信分享功能,中间走了很多弯路,在此做一下小结,希望对在应用中使用到微信分享 ...

EXT4 Store Load For Gird Exception

Gird Store 自动装载时附加一个参数user,而在pagingtoolbar上点击获取下一页数 ...

一个效果很华丽的仿桌面APP,却胜似Launcher

开发Android APP的同学是否对于Launcher实现的绚丽效果而痴迷呢?什么,连Android ...

Spring Data: a new perspective of data operations

Spring Data: a new perspective of data operations ...

Android实现换肤功能(一)

上周有个朋友给建议说讲讲换肤吧,真巧这周公司的工作安排也有这个需求,换的地方之多之繁,让人伤神死了。正 ...

最新问答

更多

从分组数据中选择第一行和最后一行(Select first and last row from grouped data)

可能有一个更快的方法: df %>% group_by(id) %>% arrange(stopSequence) %>% filter(row_number()==1 | row_number()==n()) There is probably a faster way: df %>% group_by(id) %>% arrange(stopSequence) %>% filter(row_number()==1 | row_number()==n())

在挂架中使用重定向时出错(Error using redirect in pylons)

尝试: from pylons import url from pylons.controllers.util import redirect # ... redirect(url(controller='formtest', action='result')) 您最好使用当前的Pylons 1.0文档和1.0更新的QuickWiki教程 ,以及网站上的其他参考资料。 Try: from pylons import url from pylons.controllers.util impor

Perl:比较两个文件并打印匹配和不匹配的数据(Perl: Comparing two files and printing data that match and don't match)

如果你有足够的内存,使用散列。 如果符号在input1.txt中不会出现多次(即如果AB在文件中,则AX不是),下面的代码应该可以工作: #!/usr/bin/perl use warnings; use strict; my %hash; open my $F1, '<', 'input1.txt' or die $!; while (<$F1>) { my @values = split / /; @hash{@values} = reverse @values; } c

(R - > R)函数的简单自动分类(Simple Automatic Classification of the (R-->R) Functions)

Scipy具有拟合数据的功能 ,但它们使用多项式或样条函数 。 您可以使用Gauß的许多发现之一 , 最小二乘法来适应其他功能。 Scipy has functions for fitting data, but they use polynomes or splines. You can use one of Gauß' many discoveries, the method of least squares to fit other functions.

ISS错误CS0433:名称冲突(ISS error CS0433: name collision)

我在MSDN中找到了描述此错误的链接。 总而言之,在页面的文件名(TimeLogTab.aspx)和后面的代码(公共类TimeLogTab)中的类之间会发生命名冲突。 链接建议重命名其中的一个。 我将课程改为Time_LogTab,错误消失了。 I found a link in the MSDN that describes this error. To summarize, a naming conflict can happen between the file name of a pag

使用MvvmCross动态加载UIViewController(Loading a UIViewController Dynamically with MvvmCross)

您是否将MyVcViewModel绑定到您的MyVc ? 如果MyVc可成功用作根/子导航模式,请尝试将其显示为内容(也许您可以将其放在ViewDidLoad()事件中): var vmRequest = MvxViewModelRequest.GetDefaultRequest(typeof(MyVcViewModel)); var viewController = new MvxViewController(); var myView = viewController.CreateView

批量脚本循环(Batch script loop)

for /l是你的朋友: for /l %x in (1, 1, 100) do echo %x 从1开始,逐个开始,并以100完成。 如果它在批处理文件中,请使用两% s for /l %%x in (1, 1, 100) do echo %%x (这是我真的很讨厌Windows脚本的事情之一) 如果循环的每次迭代都有多个命令,请执行以下操作: for /l %x in (1, 1, 100) do ( echo %x copy %x.txt z:\whatever\etc )

以json的形式存储localstorage值(store the localstorage value in the form of json)

只需构建一个对象,然后对其进行stringify 。 例如,如果我假设您的input元素的名称是您要在对象上使用的名称: $('.proceed_btn').on('click', function(){ // Blank to start with var order = {}; // Loop through all inputs... $('input[type="text"], input[type="text"]').each(function(){

福州市闽侯县上街中心学校外来户口要怎样申请

登陆“闽侯县政府门户网站”首页> 公共服务 > 教育学习 > 入学政策一、办理程序 1、申请者持三证(暂住证、务工证或劳动合同、原籍户口簿)的原件及复印件到暂住地所在乡镇中心小学申请; 2、乡镇中心小学负责对申请人资料进行审核,符合入学条件的,根据上级要求参加电脑派位,电脑派位不成功的给予统筹安排; 3、申请人根据公示的电脑派位的结果或统筹安排的结果到指定的学校办理入学注册手续。 二、提供材料 1、原籍户口簿原件及复印件; 2、暂住证(居住半年以上)、务工证或劳动合同。

Python:如何将生成器迭代值附加到列表中(Python: How to append generator iteration values to a list)

您的生成器不会产生新列表,它会一遍又一遍地生成相同的列表 。 当你追加那个产生的引用你只能看到相同的原始列表,在它最近洗牌的形式,一遍又一遍。 产生一份副本: def poss_comb(coord): coord = coord[:] # use a local copy of the list random.shuffle(coord) yield coord 或创建随机排序,而不是使用sorted()函数进行inplace shuffling: def poss