JavaScriptにjsonにシリアライズするサンプルコード
参考コード:
SerializeJsonToStr : function( objectJson )
{
if( objectJson == null )
return “null";
if( typeof(objectJson) == typeof(0) )
return objectJson.toString();
if( typeof(objectJson) == typeof(") ||
objectJson instanceof String )
{
objectJson = objectJson.toString();
objectJson = objectJson.replace( //r/n/, '//r//n’);
objectJson = objectJson.replace( //n/, '//n’);
objectJson = objectJson.replace( //"/, '//"');
return '"' + objectJson + '"';
}
if( objectJson instanceof Array )
{
var strRet = “[“;
for( var i = 0; i < objectJson.length; i++) { if( strRet.length > 1 )
strRet += “,";
strRet += ExternalInterface.SerializeJsonToStr(objectJson[i]);
}
strRet += “]";
return strRet;
}
if( typeof(objectJson) == typeof({}) )
{
var strRet = “{“;
for( var p in objectJson )
{
if( strRet.length > 1 )
strRet += “,";
strRet += p.toString() + ':’ + ExternalInterface.SerializeJsonToStr(objectJson[p]);
}
strRet += “}";
return strRet;
}
}