zoukankan      html  css  js  c++  java
  • Json

    最近最折腾的及时Json了。不知道是自己太笨,还是自己太笨,不过还好,就不要求我的搭档再费劲去改服务器的数据了,反正都要弄懂,那就现在开始行动吧。

        说实话,以前真不知道Json是个什么恶具体情况,直到这几天的折腾,unders。。。it!

    首先,我们要传一个请求过去,然后,我们服务器得到请求,根据请求来获知客户端需要什么东西,然后在将自己是否有客户端需要的东西有木有饭后一个code回去,然后客户端根据服务端返回的code来判断服务端是否有自己需要的东西。然后最后一次就是一次fetch方式,然后带着自己的大口袋,去将自己需要的东西给装回来。

         然后这边客户端把得到的数据然后解析出来,只是这边解析需要根据自己接受到的数据的一些存储的方式,然后这边来定义一个类似于接口的实体类,这样根据相同的字段来获得数据库里面的字段内容。

        这里呢!我只是将我觉得有点绕的解析贴出来,还要他对应的图(服务器):

        JSONObject jsonObject = new JSONObject(WelcomeActivity.WORDS_REQUEST);
            Grade_List = new ArrayList<String>();
    
            grade = new ArrayList<GradeListInfo>();
            course = new ArrayList<CourseListInfo>();
            classs = new ArrayList<ClassListInfo>();
            words = new ArrayList<WordsInfo>();
            // there itemsName is items
            itemsName = jsonObject.keys().next().toString();
            Iterator grade_Itr = jsonObject.getJSONObject(itemsName).keys();
            while (grade_Itr.hasNext()) {
                grade_List = new GradeListInfo();
                grade_List.grade_Name = grade_Itr.next().toString();
       
            }
        
            Iterator course_Itr = jsonObject.getJSONObject(itemsName)
                    .getJSONObject(grade_List.grade_Name).keys();
            while (course_Itr.hasNext()) {
    
                course_List = new CourseListInfo();
                course_List.course_Name = course_Itr.next().toString();// -----------------to add the class
                // to define the classlist
                Iterator classItr = jsonObject.getJSONObject(itemsName)
                        .getJSONObject(grade_List.grade_Name)
                        .getJSONObject(course_List.course_Name).keys();
                while (classItr.hasNext()) {
    
                    class_List = new ClassListInfo();
                    wordsInfo = new WordsInfo();
                    class_List.class_Name = classItr.next().toString();
    
                    wordsInfo.id = jsonObject.getJSONObject(itemsName)
                            .getJSONObject(grade_List.grade_Name)
                            .getJSONObject(course_List.course_Name)
                            .getJSONObject(class_List.class_Name).getInt("id");
                    wordsInfo.create_time = (jsonObject.getJSONObject(itemsName)
                            .getJSONObject(grade_List.grade_Name)
                            .getJSONObject(course_List.course_Name)
                            .getJSONObject(class_List.class_Name)
                            .getString("create_time"));
                    wordsInfo.jpg_url = (jsonObject.getJSONObject(itemsName)
                            .getJSONObject(grade_List.grade_Name)
                            .getJSONObject(course_List.course_Name)
                            .getJSONObject(class_List.class_Name)
                            .getString("jpg_url"));
                    wordsInfo.wav_url = (jsonObject.getJSONObject(itemsName)
                            .getJSONObject(grade_List.grade_Name)
                            .getJSONObject(course_List.course_Name)
                            .getJSONObject(class_List.class_Name)
                            .getString("wav_url"));
                    if ((jsonObject.getJSONObject(itemsName)
                            .getJSONObject(grade_List.grade_Name)
                            .getJSONObject(course_List.course_Name)
                            .getJSONObject(class_List.class_Name)
                            .getString("en_name").equals(""))) {
                        wordsInfo.en_name = wordsInfo.jpg_url.substring(30,
                                wordsInfo.jpg_url.length() - 4);
                    } else {
    
                        wordsInfo.en_name = (jsonObject.getJSONObject(itemsName)
                                .getJSONObject(grade_List.grade_Name)
                                .getJSONObject(course_List.course_Name)
                                .getJSONObject(class_List.class_Name)
                                .getString("en_name"));
                    }
    
                    words.add(wordsInfo);
    
                    // to add the data
                    class_List.WordsList = words;
                    classs.add(class_List);
                }
    
                course_List.ClassList = classs;
                course.add(course_List);
                grade_List.CourseList = course;
                grade.add(grade_List);
                WelcomeActivity.arrayBeanInfo.GradeList = grade;

     

    反正自己觉得这次的收获还是挺大的!嘿嘿,希望你们也是哦

         

    一切只是为了充实自己!!stay hungry and stay foolish!!
  • 相关阅读:
    ssm接收界面提交的参数为空
    Servlet[jsp]的Servlet.service()引发了具有根本原因的异常无法在web.xml或使用此应用程序部署的jar文件中解析绝对uri:[http://java.sun.com/jsp/jstl/core]
    Invalid bound statement (not found)
    Data truncation: Incorrect datetime value: '' for column 'create_time' at row 1 问题
    4月29日:毕业设计计划
    4月25日:毕业设计计划
    4月24日:毕业设计计划
    4月23日:毕业设计计划
    2020年寒假学习进度(二)
    2020年寒假学习进度(一)
  • 原文地址:https://www.cnblogs.com/Catherine-Brain/p/3756047.html
Copyright © 2011-2022 走看看