Как использовать httpservice для запроса и ответа данных JSON с мобильного телефона (клиента) на сервер во Flash Builder 4.5? - PullRequest
1 голос
/ 28 июля 2011

Во-первых, я делюсь своим кодом, чтобы он был прав.

enter image description here

[Bindable]
        private var myArrayCollection:ArrayCollection;

private function serviceSend():void
        {
            var header:Object = new Object();
            header["Accept"] = "application/json";

            loginService.headers = header;
            loginService.contentType = "application/json";
            loginService.send()
        }

private function initRequest():String
        {
            jsonStr = '{"loginRequest":{"userId":"300002918","password":"ibnkcn13","language":"zh_CN"},"requestHeader":{"clientContext":{"country":"CN","channel":"IPHONE","userName":"iphoneuser","password":"password"},"serviceContext":{"serviceId":"serviceId","token":"","nonce":""},"userContext":{"userId":"sdffff","sessionId":"fsdfsdf","language":"zh_CN"}}}';       

            return jsonStr;
        }

private function onJSONResult():void
        {
             responseData = loginService.lastResult.toString();

            //loginService.resultFormat.toString();

            //responseData = responseData.replace( /\s/g, ''); 

            txt.visible=true;
            txt.text=responseData;
            trace(responseData);

            //var jd:JSONDecoder = new JSONDecoder( responseData , false);

            var obj:Object = JSON.decode(responseData);


            //var arr:Array = (JSON.decode(responseData) as Array);
            myArrayCollection = new ArrayCollection;

            var obj1:Object = new Object;
            obj1.customerName1 = obj.loginResponse.login.customerName1;
            obj1.customerName2 = obj.loginResponse.login.customerName2;


            myArrayCollection.addItem(obj1);

        }

<s:Panel visible="true" width="100%" height="100%"
                 title="HTTPService">
            <s:DataGrid id="dgPosts1" width="100%" height="100%"
                        dataProvider="{myArrayCollection}">
                <s:columns>
                        <s:ArrayList>
                            <s:GridColumn dataField="customerName2"
                                          headerText="customerName2"/>
                            <s:GridColumn dataField="customerName1"
                                          headerText="customerName1"/>
                    </s:ArrayList>
                </s:columns>
            </s:DataGrid>
        </s:Panel> 

Тогда я хочу знать, как легко анализировать каждое значение данных json? я хочу разобрать эти данные JSON, как это и как это сделать enter image description here просто как:

var jd:JSONDecoder = new JSONDecoder( responseData , false);
dgPosts1.dataProvider = jd as ArrayCollection;

<s:DataGrid id="dgPosts1" width="100%" height="100%"
                        dataProvider="{myArrayCollection}">
                <s:columns>
                    <json:JSONDecoder>
                        <json:id>
                                                       ...................
                        </json:id>
                    </json:JSONDecoder>

код не выполнен. я хочу знать, как использовать in datagrid для разбора поставщика данных json? Большое спасибо.

...