访问json类中的字段值

时间:2016-12-07 09:49:29

标签: jquery json

根据以下内容我有一个json类:

    [
    {
"AnswerDate": "2016-06-06T00:00:00",
"TOTE": 1,
"Title2": "شاخص های عمومی ارزیابی عملکرد",
"ExpireDate": "1395/03/17",
"TemplateID": 4259,
"EFQMPivotID": 1,
"Title": "برنامه مهندسی نقش و ساختار دولت",
"Wieght": 240.00000000,
"Value": "239.70464100",
"CountPivot": "true",
"AnswerExpireDate": "2016-06-06T00:00:00",
"GrantStart": "2016-05-10T00:00:00",
"Status":     "True,True,True,False,False,False,True,True,True,True,True,False,False,False,False,False,False,True,True,True,False,False,False,False,1,True,False,2,False,False,False,0,1,1"}
 ]

我想访问获取此值的值status字段并传递给jquery。 请帮帮我。

3 个答案:

答案 0 :(得分:1)

假设您的json数组为数据。现在你可以使用" var status = $。parseJSON(data)",它会给你一个正常的数组。现在,如果您想要访问状态,则可以使用状态[' status']。它将返回状态值。 [编辑]

<pre><code>
   var jsonObj=   [
    {
        "AnswerDate": "2016-06-06T00:00:00",
        "TOTE": 1,
        "Title2": "شاخص های عمومی ارزیابی عملکرد",
        "ExpireDate": "1395/03/17",
        "TemplateID": 4259,
        "EFQMPivotID": 1,
        "Title": "برنامه مهندسی نقش و ساختار دولت",
        "Wieght": 240.00000000,
        "Value": "239.70464100",
        "CountPivot": "true",
        "AnswerExpireDate": "2016-06-06T00:00:00",
        "GrantStart": "2016-05-10T00:00:00",
        "Status":"True,True,True,False,False,False,True,True,True,True,True,False,False,False,False,False,False,True,True,True,False,False,False,False,1,True,False,2,False,False,False,0,1,1"
    }
 ];
    var res=$.parseJSON[jsonObj];
    console.log(res['Status']);
</code></pre>

答案 1 :(得分:0)

尝试

var arr = [
    {
"AnswerDate": "2016-06-06T00:00:00",
"TOTE": 1,
"Title2": "شاخص های عمومی ارزیابی عملکرد",
"ExpireDate": "1395/03/17",
"TemplateID": 4259,
"EFQMPivotID": 1,
"Title": "برنامه مهندسی نقش و ساختار دولت",
"Wieght": 240.00000000,
"Value": "239.70464100",
"CountPivot": "true",
"AnswerExpireDate": "2016-06-06T00:00:00",
"GrantStart": "2016-05-10T00:00:00",
"Status":     "True,True,True,False,False,False,True,True,True,True,True,False,False,False,False,False,False,True,True,True,False,False,False,False,1,True,False,2,False,False,False,0,1,1"}
 ]
var getStatusField = arr[0].Status.split(",");
var getLast = getStatusField [getStatusField.length-1];
console.log(getLast);

答案 2 :(得分:0)

尝试使用JavaScript split()方法来拆分Status属性的fileprivate var timer = Timer() fileprivate var textField = UITextField() //change to your field override func viewDidLoad() { super.viewDidLoad() let longPress = UILongPressGestureRecognizer(target: self, action: #selector(longPress(_:))) textField.addGestureRecognizer(longPress) } func longPress(_ guesture: UILongPressGestureRecognizer) { if guesture.state == UIGestureRecognizerState.began { longPressBegun(guesture) } else if guesture.state == UIGestureRecognizerState.changed { //longPressStateChanged(guesture) } else if guesture.state == UIGestureRecognizerState.ended { longPressEnded() } else if guesture.state == UIGestureRecognizerState.cancelled { longPressCancelled() } } func longPressBegun(_ guesture: UILongPressGestureRecognizer) { timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(repeatAction), userInfo: nil, repeats: true) } func longPressEnded() { timer.invalidate() } func longPressCancelled() { timer.invalidate() } func repeatAction() { deleteBackward() } 分隔值。

工作演示:

,