Java 将JSON数据配对为字符串

Java 将JSON数据配对为字符串,java,android,json,Java,Android,Json,我尝试将json文件解析为字符串,以使用它在listview中显示此日期。我尝试像课程的视频一样显示此日期,但我有此错误,但在视频中它可以工作 public class QueryUtils { private QueryUtils(){ } private final static String QUERY_UTILS_URL = "{ \"kind\": \"books#volumes\", \"to

我尝试将json文件解析为字符串,以使用它在listview中显示此日期。我尝试像课程的视频一样显示此日期,但我有此错误,但在视频中它可以工作

 public class QueryUtils {

    private QueryUtils(){
    }
    private final static String QUERY_UTILS_URL = "{  \"kind\": \"books#volumes\",  \"totalItems\": 392,  \"items\": [    {      \"kind\": \"books#volume\",      \"id\": \"qKFDDAAAQBAJ\",      \"etag\": \"REv5wZ4Dkek\",      \"selfLink\": \"https://www.googleapis.com/books/v1/volumes/qKFDDAAAQBAJ\",      \"volumeInfo\": {        \"title\": \"Android\",        \"authors\": [          \"P.K. Dixit\"        ],        \"publisher\": \"Vikas Publishing House\",        \"publishedDate\": \"2014\",        \"description\": \"Android is a movement that has transferred data from laptop to hand-held devices like mobiles. Though there are alternate technologies that compete with Android, but it is the front runner in mobile technology by a long distance. Good knowledge in basic Java will help you to understand and develop Android technology and apps. Many universities in India and across the world are now teaching Android in their syllabus, which shows the importance of this subject. This book can be read by anyone who knows Java and XML concepts. It includes a lot of diagrams along with explanations to facilitate better understanding by students. This book aptly concludes with a project that uses Android, which will greatly benefit students in learning the practical aspects of Android. Key Features • Instructions in designing different Android user interfaces • Thorough explanations of all activities • JSON • Android-based project to aid practical understanding\",        \"industryIdentifiers\": [          {            \"type\": \"ISBN_13\",            \"identifier\": \"9789325977884\"          },          {            \"type\": \"ISBN_10\",            \"identifier\": \"9325977885\"          }        ],        \"readingModes\": {          \"text\": false,          \"image\": true        },        \"pageCount\": 372,        \"printType\": \"BOOK\",        \"categories\": [          \"Computers\"        ],        \"averageRating\": 3,        \"ratingsCount\": 1,        \"maturityRating\": \"NOT_MATURE\",        \"allowAnonLogging\": true,        \"contentVersion\": \"preview-1.0.0\",        \"panelizationSummary\": {          \"containsEpubBubbles\": false,          \"containsImageBubbles\": false        },        \"imageLinks\": {          \"smallThumbnail\": \"http://books.google.com/books/content?id=qKFDDAAAQBAJ&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api\",          \"thumbnail\": \"http://books.google.com/books/content?id=qKFDDAAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api\"        },        \"language\": \"en\",        \"previewLink\": \"http://books.google.com.eg/books?id=qKFDDAAAQBAJ&printsec=frontcover&dq=android&hl=&cd=1&source=gbs_api\",        \"infoLink\": \"https://play.google.com/store/books/details?id=qKFDDAAAQBAJ&source=gbs_api\",        \"canonicalVolumeLink\": \"https://play.google.com/store/books/details?id=qKFDDAAAQBAJ\"      },      \"saleInfo\": {        \"country\": \"EG\",        \"saleability\": \"FOR_SALE\",        \"isEbook\": true,        \"listPrice\": {          \"amount\": 236.25,          \"currencyCode\": \"EGP\"        },        \"retailPrice\": {          \"amount\": 236.25,          \"currencyCode\": \"EGP\"        },        \"buyLink\": \"https://play.google.com/store/books/details?id=qKFDDAAAQBAJ&rdid=book-qKFDDAAAQBAJ&rdot=1&source=gbs_api\",        \"offers\": [          {            \"finskyOfferType\": 1,            \"listPrice\": {              \"amountInMicros\": 236250000,              \"currencyCode\": \"EGP\"            },            \"retailPrice\": {              \"amountInMicros\": 236250000,              \"currencyCode\": \"EGP\"            }          }        ]      },      \"accessInfo\": {        \"country\": \"EG\",        \"viewability\": \"PARTIAL\",        \"embeddable\": true,        \"publicDomain\": false,        \"textToSpeechPermission\": \"ALLOWED\",        \"epub\": {          \"isAvailable\": false        },        \"pdf\": {          \"isAvailable\": true,          \"acsTokenLink\": \"http://books.google.com.eg/books/download/Android-sample-pdf.acsm?id=qKFDDAAAQBAJ&format=pdf&output=acs4_fulfillment_token&dl_type=sample&source=gbs_api\"        },        \"webReaderLink\": \"http://play.google.com/books/reader?id=qKFDDAAAQBAJ&hl=&printsec=frontcover&source=gbs_api\",        \"accessViewStatus\": \"SAMPLE\",        \"quoteSharingAllowed\": false      },      \"searchInfo\": {        \"textSnippet\": \"Many universities in India and across the world are now teaching Android in their syllabus, which shows the importance of this subject. This book can be read by anyone who knows Java and XML concepts.\"}}]}";

    public static ArrayList<CustomBookModel> bookModels (){
        ArrayList<CustomBookModel> bookModelArrayList = new ArrayList<>();

        try{
            JSONObject books = new JSONObject(QUERY_UTILS_URL);
            JSONArray booksArray = new JSONArray("items");
            for (int i = 0 ;i < booksArray.length() ;i++ ){
                JSONObject currentBook =booksArray.getJSONObject(i);
                JSONObject infoVolumes = currentBook.getJSONObject("volumeInfo");
                String title = infoVolumes.getString("title");
                String author = infoVolumes.getString("authors");

                CustomBookModel book = new CustomBookModel(title ,author);
                bookModelArrayList.add(book);
            }
        } catch (Exception e) {
           Log.e("QueryUtils" , "problem parsing ...." , e);
        }
        return bookModelArrayList;
    }}
公共类查询tils{
私有查询单元(){
}
私有最终静态字符串查询\u UTILS\u URL=“{\'kind\”:\“books\35; volumes\”,\“totalItems\”:392,\“items\”:[{\'kind\”:“books\35; volume\”,\“id\”:“qKFDDAAAQBAJ\”,“etag\:“REv5wZ4Dkek\”,“selfLink\”:“https://www.googleapis.com/books/v1/volumes/qKFDDAAAQBAJ\“,\“volumeInfo\”:{\“title\”:\“Android\“,”作者\“:[\”P.K.迪克西特\“],”出版商\“:”维卡斯出版社\“,”出版日期\“:”2014 \“,”描述\“:\"安卓是一项将数据从笔记本电脑传输到手机等手持设备的运动。虽然有替代技术与安卓竞争,但它在移动技术领域遥遥领先。掌握基础Java知识将帮助你理解和开发安卓技术和应用程序。安卓的许多大学印度和全世界现在都在教学大纲中教授Android,这表明了这门学科的重要性。任何了解Java和XML概念的人都可以阅读这本书。这本书包括许多图表和解释,以便于学生更好地理解。这本书以一个使用Android的项目作为恰当的结论,该项目使用了在学习Android的实践方面,学生将受益匪浅。主要功能•设计不同Android用户界面的说明•对所有活动的全面解释•JSON•基于Android的项目,以帮助实际理解\“,”行业标识\“:[{“type\”:\”ISBN U 13\“,”标识符\“:\”9789325977884\”,“{”类型\“:\”ISBN\U 10\“,”标识符\“:\”9325977885\”,““阅读模式\“:{”文本\“:假,\”图像\“:真,\”页面计数\“:372,\”打印类型\“:”书籍\“,”类别\”:[\'Computers\'],\'averageRating\':3,\'ratingsCount\':1,\'DurationTyrating\':\'NOT\'u Duration\',\'allowAnonLogging\':true,\'contentVersion\':\'preview-1.0.0\',\'panelizationSummary\':{\'ContainesSubbubbles\':false,\'ContainesImageBubbles\':false},“imageLinks\:{\“smallThumbnail\”:\“http://books.google.com/books/content?id=qKFDDAAAQBAJ&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api\“,\“缩略图\”:\”http://books.google.com/books/content?id=qKFDDAAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api\},“语言”:“en”,“预览链接”:“http://books.google.com.eg/books?id=qKFDDAAAQBAJ&printsec=frontcover&dq=android&hl=&cd=1&source=gbs_api\“,\”信息链接\“:\”https://play.google.com/store/books/details?id=qKFDDAAAQBAJ&source=gbs_api\“,\“canonicalVolumeLink\”:\”https://play.google.com/store/books/details?id=qKFDDAAAQBAJ\"      },      \“saleInfo\”:{“country\”:“EG\”,“saleability\”:“FOR\u SALE\”,“isEbook\”:true,““listPrice\”:{“amount\”:{“amount\”:“currencyCode\”:“EGP\”,“retailPrice\”:{“amount\”:236.25,““currencyCode\”:“EGP\”,“buyLink\:”https://play.google.com/store/books/details?id=qKFDDAAAQBAJ&rdid=book-qKFDDAAAQBAJ&rdot=1&source=gbs\U api\,“报价单”:[{“finskyOfferType\”:1,“价格单”:{“amountInMicros\”:236250000,“货币代码”:“EGP\”},“零售价”:{”amountInMicros\:236250000、\“currencyCode\”:\“EGP\”}]、\“accessInfo\”:{“国家”:“EG\”、\“可视性\”:“部分性\”、\“可嵌入性\”:true、\“公共域\”:false、\“textToSpeechPermission\”:“允许的”、“epub\”:{I可用\“:false},\'pdf\':{\'isAvailable\':true,\'acsTokenLink\':\”http://books.google.com.eg/books/download/Android-sample-pdf.acsm?id=qKFDDAAAQBAJ&format=pdf&output=acs4_fulfillment_token&dl_type=sample&source=gbs_api\“},\“webReaderLink\”:\"http://play.google.com/books/reader?id=qKFDDAAAQBAJ&hl=&printsec=frontcover&source=gbs_api\“,\“accessViewStatus\”:\“SAMPLE\”,\“QuoteShareGallowed\”:false},\“searchInfo\”:{“textSnippet\”:\”印度和世界各地的许多大学现在都在教学大纲中教授Android,这表明了这门学科的重要性;
公共静态ArrayList bookModels(){
ArrayList bookModelArrayList=新建ArrayList();
试一试{
JSONObject books=新的JSONObject(QUERY\u UTILS\u URL);
JSONArray booksArray=新的JSONArray(“项目”);
对于(int i=0;i
但我在logcat中有这个错误

 10-26 11:47:34.575 10591-10591/? I/art: Late-enabling -Xcheck:jni
    10-26 11:47:34.575 10591-10591/? I/art: VMHOOK: rlim_cur : 0 pid:10591
    10-26 11:47:34.653 10591-10591/com.example.bookslist W/System: ClassLoader referenced unknown path: /data/app/com.example.bookslist-1/lib/arm
    10-26 11:47:34.703 10591-10591/com.example.bookslist W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
    10-26 11:47:34.771 10591-10591/com.example.bookslist I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>
    10-26 11:47:34.772 10591-10591/com.example.bookslist I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>
    10-26 11:47:34.911 10591-10591/com.example.bookslist E/QueryUtils: problem parsing ....
        org.json.JSONException: Value items of type java.lang.String cannot be converted to JSONArray
            at org.json.JSON.typeMismatch(JSON.java:111)
            at org.json.JSONArray.<init>(JSONArray.java:96)
            at org.json.JSONArray.<init>(JSONArray.java:108)
            at com.example.bookslist.QueryUtils.bookModels(QueryUtils.java:21)
            at com.example.bookslist.MainActivity.onCreate(MainActivity.java:17)
            at android.app.Activity.performCreate(Activity.java:6248)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1125)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2437)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2544)
            at android.app.ActivityThread.access$900(ActivityThread.java:150)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:168)
            at android.app.ActivityThread.main(ActivityThread.java:5845)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
    10-26 11:47:35.029 10591-10605/com.example.bookslist I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: Nondeterministic_AU_msm8974_LA.BF.1.1.3__release_AU (I3fa967cfef)
        OpenGL ES Shader Compiler Version: E031.28.00.02
        Build Date: 09/29/15 Tue
        Local Branch: mybranch14683032
        Remote Branch: quic/master
        Local Patches: NONE
        Reconstruct Branch: NOTHING
10-26 11:47:34.575 10591-10591/?I/art:Late enabling-Xcheck:jni
10-26 11:47:34.575 10591-10591/?I/art:VMHOOK:rlim_cur:0 pid:10591
1.
public static ArrayList<CustomBookModel> bookModels (){
    ArrayList<CustomBookModel> bookModelArrayList = new ArrayList<>();

    try{
        JSONObject books = new JSONObject(QUERY_UTILS_URL);
        JSONArray booksArray = books.getJSONArray("items");
        for (int i = 0 ;i < booksArray.length() ;i++ ){
            JSONObject currentBook =booksArray.getJSONObject(i);
            JSONObject infoVolumes = currentBook.getJSONObject("volumeInfo");
            String title = infoVolumes.getString("title");
            String author = infoVolumes.getString("authors");

            CustomBookModel book = new CustomBookModel(title ,author);
            bookModelArrayList.add(book);
        }
    } catch (Exception e) {
       Log.e("QueryUtils" , "problem parsing ...." , e);
    }
    return bookModelArrayList;
}}