Код: Выделить всё
import flash.display.*;import com.adobe.serialization.json.JSON; var loader:URLLoader = new URLLoader(); var request:URLRequest = new URLRequest("test.json"); // содержимое файла [{"uid": "1","first_name": "qqq","last_name": "xxx", "location": {"country": "zzz","city": "aaa"} },{"uid": "2","first_name": "eee","last_name": "rrr","location": {"country": "ttt","city": "nnn"} }]loader.load(request); var json_str = '[{"uid": "1","first_name": "qqq","last_name": "xxx", "location": {"country": "zzz","city": "aaa"} },{"uid": "2","first_name": "eee","last_name": "rrr","location": {"country": "ttt","city": "nnn"} }]'; var json_data:Array = JSON.decode(json_str); result_tf.text += "Отдельный вывод: \n"; result_tf.text += "\nID: " + json_data[0].uid;result_tf.text += "\nИмя: " + json_data[0].first_name;result_tf.text += "\nФамилия: " + json_data[0].last_name;result_tf.text += "\nСтрана: " + json_data[0].location.country;result_tf.text += "\nГород: " + json_data[0].location.city; result_tf.text += "\nID: " + json_data[1].uid;result_tf.text += "\nИмя: " + json_data[1].first_name;result_tf.text += "\nФамилия: " + json_data[1].last_name;result_tf.text += "\nСтрана: " + json_data[1].location.country;result_tf.text += "\nГород: " + json_data[1].location.city; result_tf.text += "\n\nМассовый вывод: \n"; for (var key:Object in json_data){ result_tf.text += "\nID: " + json_data[key].uid; result_tf.text += "\nИмя: " + json_data[key].first_name; result_tf.text += "\nФамилия: " + json_data[key].last_name; result_tf.text += "\nСтрана: " + json_data[key].location.country; result_tf.text += "\nГород: " + json_data[key].location.city;}
Пробовал делать так:
Код: Выделить всё
var json_str = loader.data;
Код: Выделить всё
var json_str = '[{"uid": "1","first_name": "qqq","last_name": "xxx", "location": {"country": "zzz","city": "aaa"} },{"uid": "2","first_name": "eee","last_name": "rrr","location": {"country": "ttt","city": "nnn"} }]';
.TypeError: Error #1009: Не удается вызвать свойство или метод со ссылкой на объект "null".
at com.adobe.serialization.json::JSONTokenizer/nextChar()
at com.adobe.serialization.json::JSONTokenizer()
at com.adobe.serialization.json::JSONDecoder()
at com.adobe.serialization.json::JSON$/decode()
at json2_fla::MainTimeline/frame1()
Помогите, пожалуйста, с вышеописанной проблемой.
Заранее спасибо.