Javascript 访问多个JSON数组中的元素

Javascript 访问多个JSON数组中的元素,javascript,arrays,json,Javascript,Arrays,Json,我使用JSON Simple创建了以下JSON 问题: { "Restaurant3": [ { "sentiment": "positive", "score": "0.665205", "review": "Good Indian food in campbell that's better than average at a fair price. Will come back."

我使用JSON Simple创建了以下JSON

问题:

{
    "Restaurant3": [
        {
            "sentiment": "positive",
            "score": "0.665205",
            "review": "Good Indian food in campbell that's better than average at a fair price. Will come back."
        }
    ],
    "Restaurant1": [
        {
            "sentiment": "positive",
            "score": "0.457413",
            "review": "People can say what they will about this being McIndians but I have ALWAYS had a solid meal at Tandoori Oven and was NEVER disappointed with the food.The saag lamb may be my favorite dish in the world as long as I can enjoy a cucumber salad and plenty of mint cilantro chutney to cool down my mouth. The vegetarian specials are also excellent every time. My only gripe is the menu can be a bit pricey and they have screwed around with student specials that used to get you two meals for under $10. ... Perhaps they realized it was too good of a deal?"
        }
    ],
    "Restaurant2": [
        {
            "sentiment": "positive",
            "score": "0.684585",
            "review": "We live near by and this is one of our favorite quick Indian food stop.I really like their butter chicken which is very creamy and fairly thick. The chicken inside is well spiced and grilled beforehand to give a good texture. Their baagen bharta is good as well, not as mashed up as other places and had a good mix of spice. Another thing to try is the tandoori salmon. It's juicy on the inside and crunchy on the outside. Do expect long lines during lunch, but dinner time it's fairly open."
        }
    ]
}
 List  l1 = new LinkedList(); //LinkedList.
 List  l2 = new LinkedList();
 List  l3 = new LinkedList();
 JSONObject obj2 = new JSONObject(); //JSON-Simple Library
 obj2.put("Restaurant1", l1); //I'm making a linked list and passing them to make nested json
 obj2.put("Restaurant2", l2);
 obj2.put("Restaurant3", l3);
 String answer = obj2.toJSONString();
 System.out.println(answer); //prints JSON
 return answer; //Returning entire JSON (for now)
如何从这个JSON数组中访问“情绪”、“分数”和“评论”等元素

我已经提到了这个链接,但仍然感到困惑。请帮忙 JSON:

{
    "Restaurant3": [
        {
            "sentiment": "positive",
            "score": "0.665205",
            "review": "Good Indian food in campbell that's better than average at a fair price. Will come back."
        }
    ],
    "Restaurant1": [
        {
            "sentiment": "positive",
            "score": "0.457413",
            "review": "People can say what they will about this being McIndians but I have ALWAYS had a solid meal at Tandoori Oven and was NEVER disappointed with the food.The saag lamb may be my favorite dish in the world as long as I can enjoy a cucumber salad and plenty of mint cilantro chutney to cool down my mouth. The vegetarian specials are also excellent every time. My only gripe is the menu can be a bit pricey and they have screwed around with student specials that used to get you two meals for under $10. ... Perhaps they realized it was too good of a deal?"
        }
    ],
    "Restaurant2": [
        {
            "sentiment": "positive",
            "score": "0.684585",
            "review": "We live near by and this is one of our favorite quick Indian food stop.I really like their butter chicken which is very creamy and fairly thick. The chicken inside is well spiced and grilled beforehand to give a good texture. Their baagen bharta is good as well, not as mashed up as other places and had a good mix of spice. Another thing to try is the tandoori salmon. It's juicy on the inside and crunchy on the outside. Do expect long lines during lunch, but dinner time it's fairly open."
        }
    ]
}
 List  l1 = new LinkedList(); //LinkedList.
 List  l2 = new LinkedList();
 List  l3 = new LinkedList();
 JSONObject obj2 = new JSONObject(); //JSON-Simple Library
 obj2.put("Restaurant1", l1); //I'm making a linked list and passing them to make nested json
 obj2.put("Restaurant2", l2);
 obj2.put("Restaurant3", l3);
 String answer = obj2.toJSONString();
 System.out.println(answer); //prints JSON
 return answer; //Returning entire JSON (for now)
我使用JSON Simple生成这个JSON数组:

{
    "Restaurant3": [
        {
            "sentiment": "positive",
            "score": "0.665205",
            "review": "Good Indian food in campbell that's better than average at a fair price. Will come back."
        }
    ],
    "Restaurant1": [
        {
            "sentiment": "positive",
            "score": "0.457413",
            "review": "People can say what they will about this being McIndians but I have ALWAYS had a solid meal at Tandoori Oven and was NEVER disappointed with the food.The saag lamb may be my favorite dish in the world as long as I can enjoy a cucumber salad and plenty of mint cilantro chutney to cool down my mouth. The vegetarian specials are also excellent every time. My only gripe is the menu can be a bit pricey and they have screwed around with student specials that used to get you two meals for under $10. ... Perhaps they realized it was too good of a deal?"
        }
    ],
    "Restaurant2": [
        {
            "sentiment": "positive",
            "score": "0.684585",
            "review": "We live near by and this is one of our favorite quick Indian food stop.I really like their butter chicken which is very creamy and fairly thick. The chicken inside is well spiced and grilled beforehand to give a good texture. Their baagen bharta is good as well, not as mashed up as other places and had a good mix of spice. Another thing to try is the tandoori salmon. It's juicy on the inside and crunchy on the outside. Do expect long lines during lunch, but dinner time it's fairly open."
        }
    ]
}
 List  l1 = new LinkedList(); //LinkedList.
 List  l2 = new LinkedList();
 List  l3 = new LinkedList();
 JSONObject obj2 = new JSONObject(); //JSON-Simple Library
 obj2.put("Restaurant1", l1); //I'm making a linked list and passing them to make nested json
 obj2.put("Restaurant2", l2);
 obj2.put("Restaurant3", l3);
 String answer = obj2.toJSONString();
 System.out.println(answer); //prints JSON
 return answer; //Returning entire JSON (for now)
JSON包含数组,因此必须指定子元素的索引

JSON包含数组,因此必须指定子元素的索引

JSON包含数组,因此必须指定子元素的索引


您的JSON包含数组,因此您必须为子元素指定索引

您太棒了!你的回答让我很高兴!你太棒了!你的回答让我很高兴!你太棒了!你的回答让我很高兴!你太棒了!你的回答让我很高兴!