English 中文(简体)
如何阅读json的杰华记本?
原标题:How read the json in javascript?

你能告诉我怎么用手印读杰森吗?

我有一个json 弦如铃声

 {"person":{"First name":"Dharmalingm","Last name":"Arumugam","Address":{"door number":"123","street":"sample street","city":"sample_city"},"phone number":{"mobile":"0123","landline":"01234","skype":"01235"}}}

我想读读 < enger> skype 的电话号码

最佳回答

这应该能让你上路

var o = {"person":{"First name":"Dharmalingm","Last name":"Arumugam","Address":{"door number":"123","street":"sample street","city":"sample_city"},"phone number":{"mobile":"0123","landline":"01234","skype":"01235"}}}

o["person"]["phone number"]["skype"];

/* or */

o.person["phone number"]["skype"];
问题回答

如果您是以 JSON 字符串开头, 请以 < code> 1 开头。 如果您已经有 JS 对象, 请跳转到 < code> 2 。

  1. 使用“https:// developmenter.mozilla.org/en/javaScript/Reference/Global_Objects/Json/parse” rel=“nofollow”\\code>Json.parse () 将JSon字符串转换为 JSON 的 JSON 对象。 支持 的浏览器, 一个没有本地 JSON < /a> 的浏览器, 您可以使用 < a href= 来实施它。

    var jsondata = JSON.parse( {"person":{"First name":"Dharmalingm","Last name":"Arumugam","Address":{"door number":"123","street":"sample street","city":"sample_city"},"phone number":{"mobile":"0123","landline":"01234","skype":"01235"}}} );
    
  2. 从 JUS 对象中获取您通常一样的数值

    var skype = jsondata.person[ phone number ].skype;
    

此处的代码完整, 样本 :

var jsondata = JSON.parse( {"person":{"First name":"Dharmalingm","Last name":"Arumugam","Address":{"door number":"123","street":"sample street","city":"sample_city"},"phone number":{"mobile":"0123","landline":"01234","skype":"01235"}}} );

//normally, the dot-notation is used
//but since "phone number" is not a valid key when using dot-notation
//the bracket notation is used
var skype = jsondata.person[ phone number ].skype;

首先,它需要解析到本地的 javascript 对象, 在现代浏览器中, 可以通过 < code> Jsson.parse( json string here) 进行 ; 。 现在, 要具体获取您刚刚解析的天平号, 您需要将天花板切开。 让我们假装您通过 < code> var skypeData = Jsson.parse( json string here); , 个人天花板号码可以通过 < code> skypeData. person [phone].skype < /code > 进入。 我们必须使用 < code> [ phone number] 而不是 person. phonenumber.skype , 因为空间的原因, 。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签