/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package grammar;

import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONException;

/**
 *
 * @author Administrator
 */
public class GetFilm {
    public static String slots(String json)
            throws JSONException
    {
        //String var ="[{\"name\" : \"Behind Enemy Lines\", \"recognition\" : \"(?behind enymy lines)\" ,\"category\" : \"Action\"},{\"name\" : \"Flightplan \", \"recognition\" : \"(flight plan)\" ,\"category\" : \"Action\"},{\"name\" : \"Tomb Raider\", \"recognition\" : \"(?(lara croft) tomb raide)\" ,\"category\" : \"Action\"},{\"name\" : \"Tears of the Sun\", \"recognition\" : \"(treas of ?the sun)\" ,\"category\" : \"Action\"},{\"name\" : \"Point Break\", \"recognition\" : \"(point break)\" ,\"category\" : \"Action\"},{\"name\" : \"xXx\", \"recognition\" : \"[xxx (three x)]\" ,\"category\" : \"Action\"},{\"name\" : \"A Walk to Remember\", \"recognition\" : \"(?a walt ?to remember)\" ,\"category\" : \"Romance\"},{\"name\" : \"The Godfather\", \"recognition\" : \"(?the godfather)\" ,\"category\" : \"Crime\"}]";

        StringBuffer filmRecoSB = new StringBuffer();
        String films;

        try{
            JSONArray filmsArray =   new JSONArray(json);
            for (int x=0; x<filmsArray.length(); x++){
                JSONObject film = filmsArray.getJSONObject(x);
                if(film.has("name") && film.has("recognition"))
                    filmRecoSB.append("(" + film.getString("recognition") + ") {<choice \"" + film.getString("name") + "\">}" + "\n");
            }
            films = filmRecoSB.toString();
        }
        catch(JSONException e){
            films = "";
        }

        return films;
    }

}
