PDA

Просмотр полной версии : Декодирование загружаемых данных с сервера


Slamk2
11.01.2015, 15:26
Всем привет!
Есть код с запросом к api гугла:

my_load_vars=new LoadVars();
my_load_vars.load("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=flash");
my_load_vars.onLoad = function(){
trace(my_load_vars);
}


Если просто смотреть через браузер, то ответ будет такой:

{"responseData": {"results":[{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://get.adobe.com/ru/flashplayer/","url":"http://get.adobe.com/ru/flashplayer/","visibleUrl":"get.adobe.com","cacheUrl":"http://www.google.com/search?q\u003dcache:QQOgupyoUAoJ:get.adobe.com","title":"Adobe - Установить Adobe \u003cb\u003eFlash\u003c/b\u003e Player","titleNoFormatting":"Adobe - Установить Adobe Flash Player","content":"Нужен проигрыватель Flash Player для \nдругого компьютера?"},{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://www.adobe.com/products/flashplayer.html","url":"http://www.adobe.com/products/flashplayer.html","visibleUrl":"www.adobe.com","cacheUrl":"http://www.google.com/search?q\u003dcache:GOqnt7oPfvMJ:www.adobe.com","title":"\u003cb\u003eFlash\u003c/b\u003e Player | Adobe \u003cb\u003eFlash\u003c/b\u003e Player | Overview","titleNoFormatting":"Flash Player | Adobe Flash Player |

Но во flash данные приходят вот в таком виде:

%7B%22responseData%22%3A%20%7B%22results%22%3A%5B%7B%22GsearchResultClass%22%3A%22GwebSearch%22%2C%22unescapedUrl%22%3A%22http%3A%2F%2Fget%2Eadobe%2Ec om%2Fflashplayer%2F%22%2C%22url%22%3A%22http%3A%2F%2Fget%2Eadobe%2Ecom%2Fflashplayer%2F%22%2C%22visibleUrl%22%3A%22get%2Eadobe%2Ecom%22%2C%22cacheUrl% 22%3A%22http%3A%2F%2Fwww%2Egoogle%2Ecom%2Fsearch%3Fq%5Cu003dcache%3A7KI7McSuWgUJ%3Aget%2Eadobe%2Ecom%22%2C%22title%22%3A%22Adobe%20%2D%20Install%20Ado be%20%5Cu003cb%5Cu003eFlash%5Cu003c%2Fb%5Cu003e%20Player%22%2C%22titleNoFormatting%22%3A%22Adobe%20%2D%20Install%20Adobe%20Flash%20Player%22%2C%22cont ent%22%3A%22Cross%2Dplatform%20plugin%20plays%20animations%2C%20videos%20and%20sound%20files%20in%20%2ESWF%20format%2E%22%7D%2C%7B%22GsearchResultClas s%22%3A%22GwebSearch%22%2C%22unescapedUrl%22%3A%22http%3A%2F%2Fwww%2Eadobe%2Ecom%2Fproducts%2Fflash%2Ehtml%22%2C

Так собственно как их можно раскодировать, или как сразу получить нормальный вариант?

dark256
12.01.2015, 00:48
unescape function
unescape(string:String) : String

Evaluates the parameter x as a string, decodes the string from URL-encoded format (converting all hexadecimal sequences to ASCII characters), and returns the string.

Availability: ActionScript 1.0; Flash Player 5

Parameters
string:String - A string with hexadecimal sequences to escape.

Returns
String - A string decoded from a URL-encoded parameter.

Example
The following example shows the escape-to-unescape conversion process:


var email:String = "user@somedomain.com";
trace(email);
var escapedEmail:String = escape(email);
trace(escapedEmail);
var unescapedEmail:String = unescape(escapedEmail);
trace(unescapedEmail);


The following result is displayed in the Output panel.

user@somedomain.com
user%40somedomain%2Ecom
user@somedomain.com



Соответственно:

my_load_vars.onLoad = function(){
trace( unescape( this ) );
}

Далее читаем про JSON

http://www.flasher.ru/forum/showpost.php?p=1175269&postcount=4