Reading layer data in JSON format

80 views
Skip to first unread message

diego

unread,
Jun 24, 2013, 12:54:41 PM6/24/13
to opensca...@googlegroups.com
Hi all. I need to interact with a GeoServer that returns data in JSON format, and not GML. Does anybody have a JSON parser available that is capable of building Openscales' features, just like GMLFormat and GMLParser do?

TIA

Diego.

Shonbh

unread,
Sep 23, 2013, 10:43:49 PM9/23/13
to opensca...@googlegroups.com
I am using Geoserver 2.4 , my json response like that:
{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "id": "diem_du_lich.fid--484f8060_1414d6818fc_-7975",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -71.07057,
                    42.35791
                ]
            },
            "geometry_name": "the_geom",
            "properties": {
                "gid": 1155,
                "loai": 2,
                "mail": "",
                "telephone": "617-523-9200 ",
                "website": "http://www.frenchmemories.com/",
                "priority": 3,
                "dia_chi": "70 Charles Street Boston, MA 02108",
                "mo_ta": "<p>We welcome you to join us for a relaxing slice of France. We feature delectable French pastries, classic Parisian sandwiches, coffees and desserts. Please stop in at one of our four locations in the greater Boston area. We look forward to serving you.</p>\r\n<p>French Memories opened the first location in July 1989 in Duxbury, MA. The owners, Philippe and Debra Odier moved to the area with the intentions of opening an authentic French Patisserie.</p>\r\n<p>Philippe’s background and education gave him the knowledge to open and run the business from the front of the house to the kitchen. He grew up in the family business in Paris, his parents, grandparents and brother were all pastry chefs. He came to the USA knowing he would carry on the family tradition.  Philippe ran a wholesale bakery in Orlando, FL. He sold to the hotels, resorts, restaurants, and Burger Kings (their first croissant sandwiches).</p>\r\n<p>Bruno Biagianti joined forces with the Odiers in 1999 as a partner with a strong pastry chef background. Bruno worked in some fine shops in Paris, including the Ritz and Ladurée. He transferred with the Ritz to Boston and joined French Memories eight years later.<br /> <br /> Bruno and Philippe opened the first Café Vanille in Boston in 1999 in Beacon Hill. The shop received a warm welcome and has become The Best of Boston four times. The next café was opened in The Chestnut Hill Mall in 2001. And finally the fourth location, French Memories open in Sharon in 2008. Each location has its own design with the menus varying slightly to cater to each location.</p>",
                "lang_id": "vi",
                "ten_dvcq": "",
                "ten_ddl": "Cafe Vanille",
                "dv_dac_biet": ""
            }
        },
        {
            "type": "Feature",
            "id": "diem_du_lich.fid--484f8060_1414d6818fc_-7974",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -71.05537,
                    42.36016
                ]
            },
            "geometry_name": "the_geom",
            "properties": {
                "gid": 1082,
                "loai": 2,
                "mail": "",
                "telephone": "",
                "website": "http://www.bostoncentral.com/activities/quincy_market/p231.php",
                "priority": 2,
                "dia_chi": "Quincy Market Colonnade, Boston, MA",
                "mo_ta": "<p>Located in the heart of downtown Boston, Quincy Market is a favorite destination for both locals and tourists alike. <br /> Quincy Market combines the glories of the past and the vitality of the present with more than 50 shops, 14 restaurants, 40 food court stops and Boston's most popular comedy club. For over 250 years, the marketplace has played an integral role in the life of Boston's residents.</p>",
                "lang_id": "vi",
                "ten_dvcq": "",
                "ten_ddl": "Quincy Market",
                "dv_dac_biet": ""
            }
        }
    ],
    "crs": {
        "type": "EPSG",
        "properties": {
            "code": "4326"
        }
    }
}

HTTPservice is used to send request to Geoserver and result event is processing as following:

private function getPOIsbySearch(event:ResultEvent):void {
                var rawData:String = String(event.result);
                var arr:Object =com.adobe.serialization.json.JSON.decode(rawData);
                var array:Array=[];
                array = (arr.features as Array);
               
                var header:String='{"data": [';
                var footer:String=']};';   
                var tmp:String='';
                var i:int=0;
                for (i=0; i<=array.length-1;i++)  {
                    if (i==(array.length-1)){
                        tmp=tmp + '{"gid":"' + array[i].properties.gid + '","ten_ddl":"' + array[i].properties.ten_ddl  + '","dia_chi":"' + array[i].properties.dia_chi +   '"}'  ;
                    } else {
                        tmp=tmp + '{"gid":"' + array[i].properties.gid + '","ten_ddl":"' + array[i].properties.ten_ddl + '","dia_chi":"' + array[i].properties.dia_chi +  '"},';
                    }
                }
                tmp=header + tmp + footer;
               
                var myarray:Array=[];
                var myarr:Object =com.adobe.serialization.json.JSON.decode(tmp);
                myarray = (myarr.data as Array);
               
                var arrayColection:ArrayCollection=new ArrayCollection(myarray);
                searchList.dataProvider=arrayColection; //searchList is List component
                searchList.labelField="ten_ddl";
            }


Reply all
Reply to author
Forward
0 new messages