Some words about me

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas a urna sit amet leo sagittis cursus a at lectus. Donec bibendum facilisis ultricies. Maecenas nec arcu dui, ut lobortis erat. In nec condimentum quam. Vivamus euismod scelerisque ligula vitae fermentum. Nulla dignissim rutrum eleifend.

Donec mi eros, congue ut consectetur eget, pretium vitae orci. Aliquam pharetra ultricies lobortis. Morbi eget nisi lectus. Maecenas felis augue, molestie in vestibulum et, lacinia et leo. Suspendisse potenti. Maecenas eget est augue. Donec tincidunt mollis fermentum.

Contact me?

 
 
 

Donec mi eros, congue ut consectetur eget, pretium vitae orci. Aliquam pharetra ultricies lobortis. Morbi eget nisi lectus. Maecenas felis augue, molestie in vestibulum et, lacinia et leo. Suspendisse potenti. Maecenas eget est augue. Donec tincidunt mollis fermentum.

Send the message
 

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;

 

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

 

     

posted @ 2014-05-31 15:49  Catherine_Brain  阅读(149)  评论(0编辑  收藏  举报