我无法理解为什么在打包JSON时显示异常,比如;JSONObject无法转换为JSONArray“;在我的android项目中

我无法理解为什么在打包JSON时显示异常,比如;JSONObject无法转换为JSONArray“;在我的android项目中,android,Android,这是我的代码,我被卡住了: JSONObject jsonObj=新的JSONObject(jsonStr); Faq=jsonObj.getJSONArray(TAG_Faq) for(int i=0;i

这是我的代码,我被卡住了: JSONObject jsonObj=新的JSONObject(jsonStr); Faq=jsonObj.getJSONArray(TAG_Faq)

for(int i=0;i
谢谢大家的支持,请检查上面的代码…

//lakshman正常工作,请检查
//lakshman it work proprly please check it
 String JsonStr="[{"id":1,"creationDate":null,"updationDate":null,"creationUserId":null,"updationUserId":null,"questions":"What is Android","answer":"Android is a mobile operating system (OS) based on the Linux kernel and currently developed by Google.","deactivated":false}]";


  JSONArray jArr = new JSONArray(JsonStr);

    for (int count = 0; count < jArr.length(); count++)

     {

     JSONObject obj = jArr.getJSONObject(count);

   int id= obj.getString("id");

    String imageName = obj.getString("creationDate");
    //like that same
    }
String JsonStr=“[{“id”:1,“creationDate”:null,“updatedate”:null,“creationserid”:null,“疑问”:“什么是Android”,“回答”:“Android是基于Linux内核的移动操作系统(OS),目前由谷歌开发。”,“deactivated”:false}]; JSONArray jArr=新JSONArray(JsonStr); 对于(int count=0;count
[
{
“id”:1,
“creationDate”:空,
“更新日期”:空,
“creationUserId”:空,
“更新‌​UserId“:null,
“问题”:“什么是Android”,
“答案”:“Android是一种基于Linux内核的移动操作系统(OS),目前由谷歌开发。”,
“已停用”:错误
}
]
//这是我用以下格式解析的json数组
包com.example.jsondemo;
导入org.json.JSONArray;
导入org.json.JSONException;
导入org.json.JSONObject;
导入android.support.v7.app.ActionBarActivity;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.Menu;
导入android.view.MenuItem;
公共类MainActivity扩展了ActionBarActivity{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String jsonobj=“[{\'id\':1,\'creationDate\':null,\'updatedate\':null,\'creationserid\':null,\'updateuserid\':null,\'questions\':\'Android是什么?,\'answer\':\'Android是一个基于Linux内核的移动操作系统,目前由谷歌开发。\','deactivated\':false}';
//your json是正确的。不要混淆上面的json字符串jsut我创建的//json字符串供您理解
试一试{
JSONArray ja=新JSONArray(jsonobj);
对于(int count=0;count
寻求调试帮助的问题(“此代码为什么不起作用?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现它所需的最短代码。因为它不是
JSONObject
它是一个完全错误的
JSONArray
您的对象位于json数组中,首先获取数组,然后获取对象。请再详细说明一下。是什么代码导致了您的错误?mahadev请检查我最新更新的代码。。请给我一些建议,请发送您的json数据,我将检查[{“id”:1,“creationDate”:null,“UpdateDate”:null,“creationUserId”:null,“问题”:“什么是Android”,“回答”:“Android是一个基于Linux内核的移动操作系统(OS),目前由谷歌开发。”,“deactivated”:false}]
//lakshman it work proprly please check it
 String JsonStr="[{"id":1,"creationDate":null,"updationDate":null,"creationUserId":null,"updationUserId":null,"questions":"What is Android","answer":"Android is a mobile operating system (OS) based on the Linux kernel and currently developed by Google.","deactivated":false}]";


  JSONArray jArr = new JSONArray(JsonStr);

    for (int count = 0; count < jArr.length(); count++)

     {

     JSONObject obj = jArr.getJSONObject(count);

   int id= obj.getString("id");

    String imageName = obj.getString("creationDate");
    //like that same
    }
        [
            {
                "id": 1,
                "creationDate": null,
                "updationDate": null,
                "creationUserId": null,
                "updation‌​UserId": null,
                "questions": "What is Android",
                "answer": "Android is a mobile operating system (OS) based on the Linux kernel and currently developed by Google. ",
                "deactivated": false
            }
        ]
        //this your json array i parse in following format
        package com.example.jsondemo;

        import org.json.JSONArray;
        import org.json.JSONException;
        import org.json.JSONObject;

        import android.support.v7.app.ActionBarActivity;
        import android.os.Bundle;
        import android.util.Log;
        import android.view.Menu;
        import android.view.MenuItem;


        public class MainActivity extends ActionBarActivity {

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                String jsonobj="[{\"id\":1,\"creationDate\":null,\"updationDate\":null,\"creationUserId\":null,\"updationUserId\":null,\"questions\":\"What is Android\",\"answer\":\"Android is a mobile operating system (OS) based on the Linux kernel and currently developed by Google.\",\"deactivated\":false}]";

// yuor json is correct. don't confuse about above json string jsut I created    //json string for your understanding

                try {
                    JSONArray ja=new JSONArray(jsonobj);

                    for (int count = 0; count < ja.length(); count++)

                     {

                     JSONObject obj = ja.getJSONObject(count);

                    int ID = obj.getInt("id");
                    String CreationDate=obj.getString("creationDate");
                    String UpdationDate=obj.getString("updationDate");
                    String CreationUserId=obj.getString("creationUserId");
                    String Questions=obj.getString("questions");
                    String Answer = obj.getString("answer");
                    boolean Deactivated=obj.getBoolean("deactivated");
                    Log.d("test", "user id"+" "+ID);
                    Log.d("test", CreationDate);
                    Log.d("test", UpdationDate);
                    Log.d("test", CreationUserId);
                    Log.d("test", Questions);
                    Log.d("test", Answer);
                    Log.d("test","check"+ " "+Deactivated);

                    }
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }


        }
        //please check logcat test value it sucessfull work