最新 追記

ToDo:

  • 99 深呼吸して、おちけつ (~12/31 あと287日)
  • 98 毎日アウトプットを重きにおいた目標をたてる (~12/31 あと287日)
  • 97 買物は行動を変えるもの・ことに限る (~12/31 あと287日)
  • 96 合理的な行動はときに我慢を強いる(~12/31 あと287日)

ɥozɐʞıɥ


2012-07-01 7月なう [長年日記]

_ 7月

もう半年が経ったんだー。前半はトラブル対応のみだったな。

_ [Flash] JSONでRestful(POSTとGET)

合間を見つけてはコードをかいてみました。

ActionScriptでJSONをハンドリングするには、mikechambers/as3corelib · GitHubが便利です。

仕事ではPOSTを多用しそうです。GETが簡単ですけどね。POSTの時は配列になっているのはご愛敬です。:-P

package org.hikazoh

{

import com.adobe.serialization.json.*;

import com.adobe.serialization.json.JSON;

import flash.events.*;

import flash.net.*;

import flash.utils.*;

import mx.controls.Alert;

import mx.core.IMXMLObject;

import mx.events.FlexEvent;

import mx.events.Request;

import mx.utils.Base64Decoder;

import mx.utils.Base64Encoder;

public class RestfulJsonClient implements IMXMLObject

{

private var _doc:JsonServiceClient;

private var _requestor:URLLoader = new URLLoader();

public function RestfulJsonClient(){

}

public function initialized(doc:Object, id:String):void{

this._doc = doc as JsonServiceClient;

this._doc.addEventListener(FlexEvent.APPLICATION_COMPLETE,

loadCompleteHandler);

}

public function loadCompleteHandler(event:Event):void{

this._doc.Button01.addEventListener(MouseEvent.CLICK,

mouseClickHandler);

this._doc.Button02.addEventListener(MouseEvent.CLICK,

mousePostClickHandler);

}

public function mousePostClickHandler(event:MouseEvent):void{

var loader:URLLoader = new URLLoader();

loader.dataFormat = URLLoaderDataFormat.TEXT;

loader.addEventListener(Event.COMPLETE, completePostHandler);

var request:URLRequest = new URLRequest("http://localhost:50814/RestfulService/PostSampleMethod");

request.method = "POST";

request.contentType = "application/json";

var param:Array = [{Name: this._doc.TextInput01.text}];

request.data = new JSONEncoder(param).getString();

try{

loader.load(request);

}

catch(e:Error){

Alert.show(e.message);

}

}

public function completePostHandler(event:Event):void{

try{

this._doc.Label01.text = new JSONDecoder(event.target.data as String,false).getValue().Message;

}

catch(e:Error){

Alert.show(e.message);

}

}

public function mouseClickHandler(event:MouseEvent):void{

var urlLoader:URLLoader = new URLLoader();

urlLoader.dataFormat = URLLoaderDataFormat.TEXT;

urlLoader.addEventListener(Event.COMPLETE, completeHandler);

try{

urlLoader.load(new URLRequest("http://localhost:50814/RestfulService/GetSampleMethod/" + this._doc.TextInput01.text));

}

catch(e:Error){

trace(e.message);

}

}

public function completeHandler(event:Event):void{

try{

this._doc.Label01.text = event.target.data;

}

catch(e:Error){

trace(e.message);

}

}

}

}

_ [.NET][WCF] JSONでRestful(サーバー)

.NETのほうがJavaより慣れているのです。

using System;

using System.Collections.Generic;

using System.Linq;

using System.Runtime.Serialization;

using System.Runtime.Serialization.Json;

using System.ServiceModel;

using System.ServiceModel.Web;

using System.ServiceModel.Activation;

using System.Text;

using System.IO;

namespace RestJsonService

{

[ServiceContract]

public interface IRestfulService

{

[OperationContract]

[WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetSampleMethod/{name}")]

string GetSampleMethod(string name);

[OperationContract]

[WebInvoke(Method = "POST",

RequestFormat = WebMessageFormat.Json,

ResponseFormat = WebMessageFormat.Json,

UriTemplate = "PostSampleMethod")]

PostSampleResponse PostSampleMethod(Stream stream);

}

[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Required)]

public class RestfulService : IRestfulService

{

public string GetSampleMethod(string name)

{

return "こんにちは" + name + "さん";

}

public PostSampleResponse PostSampleMethod(Stream stream)

{

DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(PostSampleRequest[]));

PostSampleRequest [] req = (PostSampleRequest [])serializer.ReadObject(stream);

return new PostSampleResponse

{

Message = req[0].Name

};

}

}

[DataContract]

public class PostSampleRequest{

[DataMember(Name="Name")]

public string Name{ get; set;}

}

[DataContract]

public class PostSampleResponse{

[DataMember(Name="Message")]

public string Message {get; set;}

}

}

あとGlobal.asax.csで

protected void Application_Start(object sender, EventArgs e)

{

RouteTable.Routes.Add(

new ServiceRoute("RestfulService",

new WebServiceHostFactory(),

typeof(RestfulService))

);

}

_ [買物][] 面積迷路 (学研ムック)


電車の吊り広告で釣られました。解けるには解けたのだがちょっと時間がかかって悔しかった。


2012-07-04 今日は遅刻 [長年日記]

_

あまりの疲れ方にゆっくり出社

_ [映画] ラブ&ドラッグ [DVD]

観たのは先日でした。


プラダを着た悪魔 でAnne Hathawayはよかったなぁって思い今回も観ました。

内容的にはまぁまぁって感じです。


2012-07-08 疲れた [長年日記]

_ 最近

必ず土曜日出勤で疲れた。

_ [映画] シャーロック・ホームズ シャドウ ゲーム Blu-ray & DVDセット(初回限定生産)


一作目が面白かったので観ました。まぁまぁかな。次回あるような感じです。ラストは原作にちょっと忠実だったかな。


2012-07-14 久しぶりに土曜日の休み [長年日記]

_ 土曜日

ちょー久しぶりに休んだ。


2012-07-15 あつーい [長年日記]

_

かるーくランニングするつもりで外出。すっげー暑かった。6kmのうち2kmは歩いたかな。

_ [買物][Game] ニンテンドー3DS アクアブルー


ムスコへの誕生日プレゼントを買いました。

_ [買物][Game] モンスターハンター3G


ソフトはこれです。最近はずぅーーーーーーーっとこれです。


2012-07-16 夏の庭 [長年日記]


2012-07-21 Q日出勤 [長年日記]

_ Q日

本日もがんばって仕事しました。

_ [買物][映画][DVD] サマーウォーズ 期間限定スペシャルプライス版 2枚組 [DVD]


Amazonで安くなっていました。英国が米国で安く買おうと思いましたがこの価格なら国内が一番安い。


2012-07-22 久しぶりの映画館 [長年日記]

_ [映画] 映画「おおかみこどもの雨と雪」

子供たちと観てきました。今回は大人向けかな。子育て経験がある人はうんうんと頷けるかも。絵は綺麗でしたね。

_ [生活] 散髪

ようやく。久しぶり


2012-07-29 海がすき [長年日記]

_ 三浦海岸

毎年恒例の三浦海岸への海水浴です。

三浦海岸なう
三浦海岸なう posted by (C)ひかぞぉ

三浦海岸
三浦海岸 posted by (C)ひかぞぉ

波打ち際
波打ち際 posted by (C)ひかぞぉ



2002|09|10|11|12|
2003|01|02|03|04|05|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|
最新 追記