AS3 - 按内容查找JSON节点

时间:2013-06-24 14:03:48

标签: json string actionscript-3

我需要找出值 stackoverflow 所在的id。如何做到这一点?

{
 "kind": "blogList",
 "items": [
  {
   "kind": "blog",
   "id": "stackoverflow",
   "selfLink": "https://example.com",
   "posts": {
    "totalItems": 0,
    "selfLink": "https://www.foo.bar"
   },
   "pages": {
    "totalItems": 0,
    "selfLink": "https://www.example.com"
   },
   "locale": {
    "language": "en",
    "country": "",
    "variant": ""
   }
  },
  {
   "id": "google",
   "selfLink": "https://www.foo.bar",
   "posts": {
    "totalItems": 0,
    "selfLink": "https://www.test.com"
   },
   "pages": {
    "totalItems": 0,
    "selfLink": "https://www.example.com"
   },
   "locale": {
    "language": "en",
    "country": "",
    "variant": ""
   }
  },

抱歉我的英文。

1 个答案:

答案 0 :(得分:1)

尝试使用此代码,这将作为一个示例非常有用(它可以完美地工作)(之前下载此library):

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
    <mx:Script>
        <![CDATA[
            import mx.utils.ArrayUtil;
            import mx.controls.Alert;
            import lib.JSON;
            private var jsonString:String = '{"root":[{"id":"val1"},{"id":"val2"}]}';

            public function init():void{
                var decodedObj:Object = JSON.decode(jsonString);
                Alert.show(decodedObj["root"][0].id); //prints val1
                Alert.show(ArrayUtil.toArray(decodedObj["root"])[1].id); //prints val2
            }
        ]]>
    </mx:Script>
</mx:Application>
相关问题