-1

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?

tcb
  • 2,745
  • 21
  • 20
user998405
  • 1,329
  • 5
  • 41
  • 84

1 Answers1

0

I would recommend using JAX-RS for developing the web service. Specifically, as I have worked with Jersey, it supports POJO Mapping i.e. 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.

Srinivas
  • 1,780
  • 1
  • 14
  • 27
  • hi, thanks for ur answer. i try the example. But i get the error HTTP Status 404 - /RestfulExample/json/product/get – user998405 Jan 06 '13 at 07:53
  • Did you make appropriate entries in `web.xml`? Are you using the entire source code provided for download? – Srinivas Jan 06 '13 at 08:04
  • Additionally, you need to deploy the war on tomcat? Are you doing this? – Srinivas Jan 06 '13 at 08:06
  • ya. i try using the example, wat u means? deploy the war on tomcat?sorry i am new for java – user998405 Jan 06 '13 at 18:15
  • Ok you are missing few steps. Search for `Deploying war on tomcat` and `Installing tomcat` as well. Tomcat is an application server and you need to run your web service on that container. – Srinivas Jan 07 '13 at 01:07
  • Have a look at this [url](http://www.mkyong.com/maven/how-to-create-a-web-application-project-with-maven/) – Srinivas Jan 07 '13 at 01:11