码迷,mamicode.com
首页 > Web开发 > 详细

Json

时间:2014-05-31 19:10:48      阅读:310      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

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

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

 

bubuko.com,布布扣bubuko.com,布布扣

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

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

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

bubuko.com,布布扣
    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;
bubuko.com,布布扣

 bubuko.com,布布扣

bubuko.com,布布扣

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

 

     

Json,布布扣,bubuko.com

Json

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/Catherine-Brain/p/3756047.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!