简体   繁体   中英

Pass json result to sencha touch

I am new for sencha touch. I need to pass json data by using RESTful architectural .But I dun has any Idea how to start it.Can anyone guild me some example? Btw I am using JACKSON library.

Here is my java file - jsonTest.java

    package jsonTest;

import java.io.File;
import java.io.IOException;
import java.util.Map;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;



import org.codehaus.jackson.JsonEncoding;
import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

import com.sun.xml.internal.bind.api.TypeReference;



public class jsonTest {

      private static List<String> countries;
        private static List<String> tags;

         public static void main(String[] args) {

            String data = "Afghanistan, Albania, Algeria, Andorra, Angola, Antigua & Deps,"+ 
                    "United Kingdom,United States,Uruguay,Uzbekistan,Vanuatu,Vatican City,Venezuela,Vietnam,Yemen,Zambia,Zimbabwe";

            countries = new ArrayList<String>();
            StringTokenizer st = new StringTokenizer(data, ",");

            //Parse the country CSV list and set as Array
            while(st.hasMoreTokens()) {
                countries.add(st.nextToken().trim());
            }

            String strTags = "SharePoint, Spring, Struts, Java, JQuery, ASP, PHP, JavaScript, MySQL, ASP, .NET";
            tags = new ArrayList<String>();
            StringTokenizer st2 = new StringTokenizer(strTags, ",");

            //Parse the tags CSV list and set as Array
            while(st2.hasMoreTokens()) {
                tags.add(st2.nextToken().trim());
            }

        }

        public List<String> getCountryList(String query) {

            String country = null;
            query = query.toLowerCase();
            List<String> matched = new ArrayList<String>();
            for(int i=0; i < countries.size(); i++) {
                country = countries.get(i).toLowerCase();
                if(country.startsWith(query)) {
                    matched.add(countries.get(i));
                }
            }
            return matched;
        }

        public List<String> getTechList(String query) {
            String country = null;
            query = query.toLowerCase();
            List<String> matched = new ArrayList<String>();
            for(int i=0; i < tags.size(); i++) {
                country = tags.get(i).toLowerCase();
                if(country.startsWith(query)) {
                    matched.add(tags.get(i));
                }
            }
            return matched;
        }

}

How can I show the result to my sencha touch project?By using list or panel?

I would recommend using JAX-RS for developing the web service. Specifically, as I have worked with Jersey, it supports POJO Mapping ie your web service can return a POJO (Plain Old Java Object) which Jersey can implicitly convert into JSON.

Here's a working example from mkyong's website for POJO Mapping and JSON with Jersey .

PS : I have no experience in working with sencha Touch and hence can't help much with that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM