json对象访问 [英] json object accessing

查看:123
本文介绍了json对象访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这很简单,但是我坚持了下来

i know its very simple thing but i m stucked on it

我的json变量的数据如下

i have json variable with data as follow

var jsonText =
 '[ { "user": [ { "Gender": "M", "Minage": "19", "Maxage": "30", "MaritalStatusId":"0",  }] 
    }, 
    { "user":[ { "maritialtype": "Does not matter" }] 
    }, 
    { "user": [ { "Value": "No" }]
    } ]';

var jsonObject = JSON.parse(jsonText);

现在我可以以jsonObject[0].user[0].Gender

但是我无法访问maritialtypeValue

推荐答案

对于maritialtype:

jsonObject[1].user[0].maritialtype

对于Value:

jsonObject[2].user[0].Value

因为您有一个由三个对象组成的数组,用户,即一个数组或一个对象.这有点奇怪.

Because you have an array of three objects, user, which is an array or one object. It's kind of a weird structure.

这篇关于json对象访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆