无法访问 json 对象中的数据

Unable to access the data in the json object

我是新手platform.So如果有人能帮我解决这个问题就太好了。

-----> 我有一个变量 globalsyncedinData,它有以下 json 文本格式的数据。

{
    "rows": [
        {
            "key": "1234",
            "id": "1234",
            "value": {
                "rev": "1-efaa6f87b907297b8faa3423c1abbe4b"
            },
            "doc": {
                "_id": "1234",
                "_rev": "1-efaa6f87b907297b8faa3423c1abbe4b",
                "acresowned": "2000",
                "address": "6543288",
                "age": "45",
                "channels": "JAVATP",
                "email": "Windows @gmail. com",
                "gender": "Male",
                "homephone": "37884321155",
                "imageURL": "http://119.226.229.61:8080/abcd/media/0.28967773471958935IMAGE_FAR.jpg",
                "mobile": "58899110",
                "pincode": "334455",
                "qualification": "be",
                "regularcrops": "",
                "seasonalcrops": "",
                "seedbrands": "wheat",
                "soiltype": "gtred",
                "sourceofwater": "nadi",
                "state": "maharashtra",
                "username": "windows"
            }
        },
        {
            "key": "123455",
            "id": "123455",
            "value": {
                "rev": "1-bf67fc273b8e64723895d2caf7fb90d1"
            },
            "doc": {
                "_id": "123455",
                "_rev": "1-bf67fc273b8e64723895d2caf7fb90d1",
                "acresowned": "",
                "address": "",
                "age": "45",
                "channels": "JAVATP",
                "email": "win7@gmail.com",
                "gender": "Male",
                "homephone": "",
                "imageURL": "http://119.226.229.61:8080/abcd/media/0.2573327284771949IMAGE_FAR.jpg",
                "mobile": "6326678990",
                "pincode": "",
                "qualification": "be",
                "regularcrops": "",
                "seasonalcrops": "",
                "seedbrands": "",
                "soiltype": "",
                "sourceofwater": "",
                "state": "",
                "username": "win7"
            }
        },
        {
            "key": "1424951086535",
            "id": "1424951086535",
            "value": {
                "rev": "1-6f7d2dca1cc0045ec4f2d7d2aadfc31c"
            },
            "doc": {
                "_id": "1424951086535",
                "_rev": "1-6f7d2dca1cc0045ec4f2d7d2aadfc31c",
                "acresowned": "6",
                "address": "addr",
                "age": "56",
                "channels": "JAVATP",
                "email": "email@go.com",
                "gender": "Male",
                "homephone": "9999999999",
                "imageURL": "",
                "mobile": "1111111111",
                "pincode": "751059",
                "qualification": "ed qual",
                "regularcrops": "reg",
                "seasonalcrops": "seasonal",
                "seedbrands": "seed",
                "soiltype": "soil",
                "sourceofwater": "water",
                "state": "state",
                "username": "amitabh"
            }
        }
    ],
    "total_rows": 4,
    "update_seq": 10
}

我的代码片段:

function setsyncUserDetails(tx) {

     alert("globalsyncedinData: "+window.globalsyncedinData);
     alert('into setsyncUserDetails method');
     var obj = JSON.parse(window.globalsyncedinData);
     alert('parsed string into json object is:'+obj);
     alert("First key is:"+ obj.rows[0].key);
     ...
}

执行时,我一直收到警告框,直到 "parsed string into json object is [object Object]"。它停在那里。我无法访问键值,也没有看到它后面的警告框,即 alert("First key is:"+ obj.rows[0].key);打不开。

我正在 android 平台上开发应用程序,所以我需要警告框。我实际上想要一个可以从 globalsyncedinData 访问 "rows" 的变量,这样我就可以使用 $.each() 遍历每一行。我该怎么做?

在此处检查工作 fiddle。 http://jsfiddle.net/eqrmmmkz/

var text = '{"rows":[ {"key":"1234","id":"1234","value":{"rev":"1-efaa6f87b907297b8faa3423c1abbe4b"},"doc":{"_id":"1234","_rev":"1-efaa6f87b907297b8faa3423c1abbe4b","acresowned":"2000","address":"6543288","age":"45","channels":"JAVATP","email":"Windows @gmail. com","gender":"Male","homephone":"37884321155","imageURL":"http://119.226.229.61:8080/abcd/media/0.28967773471958935IMAGE_FAR.jpg","mobile":"58899110","pincode":"334455","qualification":"be","regularcrops":"","seasonalcrops":"","seedbrands":"wheat","soiltype":"gtred","sourceofwater":"nadi","state":"maharashtra","username":"windows"}} ,{"key":"123455","id":"123455","value":{"rev":"1-bf67fc273b8e64723895d2caf7fb90d1"},"doc":{"_id":"123455","_rev":"1-bf67fc273b8e64723895d2caf7fb90d1","acresowned":"","address":"","age":"45","channels":"JAVATP","email":"win7@gmail.com","gender":"Male","homephone":"","imageURL":"http://119.226.229.61:8080/abcd/media/0.2573327284771949IMAGE_FAR.jpg","mobile":"6326678990","pincode":"","qualification":"be","regularcrops":"","seasonalcrops":"","seedbrands":"","soiltype":"","sourceofwater":"","state":"","username":"win7"}} ,{"key":"1424951086535","id":"1424951086535","value":{"rev":"1-6f7d2dca1cc0045ec4f2d7d2aadfc31c"},"doc":{"_id":"1424951086535","_rev":"1-6f7d2dca1cc0045ec4f2d7d2aadfc31c","acresowned":"6","address":"addr","age":"56","channels":"JAVATP","email":"email@go.com","gender":"Male","homephone":"9999999999","imageURL":"","mobile":"1111111111","pincode":"751059","qualification":"ed qual","regularcrops":"reg","seasonalcrops":"seasonal","seedbrands":"seed","soiltype":"soil","sourceofwater":"water","state":"state","username":"amitabh"}} ], "total_rows":4,"update_seq":10}';  
obj = JSON.parse(text);  
document.getElementById("demo").innerHTML = obj.rows[0].key;    

更新:

http://jsfiddle.net/eqrmmmkz/1/