最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there a way to parse this JSON? - Stack Overflow

programmeradmin0浏览0评论

I have a JSON of following format, { "A.B.C" : "a.b.c", "C.D.E" : "c.d.e" } but I'm unable to parse this json in javascript.How can I get the value of "A.B.C"?

And I want to load this JSON in the content[] of Ember.ResourceController using load() in ember-rest.js

while loading this i got an error "Object in path A.B could not be found or was destroyed"

I have a JSON of following format, { "A.B.C" : "a.b.c", "C.D.E" : "c.d.e" } but I'm unable to parse this json in javascript.How can I get the value of "A.B.C"?

And I want to load this JSON in the content[] of Ember.ResourceController using load() in ember-rest.js

while loading this i got an error "Object in path A.B could not be found or was destroyed"

Share Improve this question edited Nov 2, 2012 at 4:58 Bala asked Nov 1, 2012 at 12:19 BalaBala 677 bronze badges 3
  • "unable to parse" why? How you try? What error you get? – user447356 Commented Nov 1, 2012 at 12:24
  • Read about Member Operators – epascarello Commented Nov 1, 2012 at 12:24
  • Did you try any thing at all? – NewUser Commented Nov 1, 2012 at 12:31
Add a ment  | 

4 Answers 4

Reset to default 7

According to jsonlint, that JSON is valid, which means you can parse it regularly:

var obj = JSON.parse('{ "A.B.C" : "a.b.c", "C.D.E" : "c.d.e" }');
var test = obj["A.B.C"]; // "a.b.c"

http://jsfiddle/88vFv/

The trick is you need to use bracket notation instead of dot notation, since your property names contain dots.

Try this:

var json = { "A.B.C" : "a.b.c", "C.D.E" : "c.d.e" };
var value = json["A.B.C"];

DId you try this?

data = JSON.parse('{ "A.B.C" : "a.b.c", "C.D.E" : "c.d.e" }')
data["A.B.C"]

Just use JSON.parse:

var values = JSON.parse('{ "A.B.C" : "a.b.c", "C.D.E" : "c.d.e" }');
var result = values['A.B.C'];
发布评论

评论列表(0)

  1. 暂无评论