如何从数组开始但没有名称的JSON数组?

时间:2015-08-10 02:50:09

标签: arrays json android-studio

我想访问数组并获取文本部分,但它是这样开始的,我不知道如何进入数组以获取它的文本部分。

[
{
    "textProns": [],
    "sourceDictionary": "ahd-legacy",
    "exampleUses": [],
    "relatedWords": [],
    "labels": [],
    "citations": [],
    "word": "car",
    "partOfSpeech": "noun",
    "attributionText": "from The American Heritage® Dictionary of the English Language, 4th Edition",
    "sequence": "0",
    "text": "An automobile.",
    "score": 0
}]

这是我的代码看起来像

public static String parseJSONForDefinition(String jsonData) throws JSONException {

    JSONArray array ;

    return null;
}

1 个答案:

答案 0 :(得分:1)

试试这个

  1. 使用com.org.json包

    String inputJson =“[{\”textProns \“:[],\”sourceDictionary \“:\”ahd-legacy \“,\”exampleUses \“:[],\”relatedWords \“:[], \“labels \”:[],\“citations \”:[],\“word \”:\“car \”,\“partOfSpeech \”:\“noun \”,\“attributionText \”:\“来自TheAmericanHeman®英语词典,第4版\“,\”序列\“:\”0 \“,\”text \“:\”汽车。\“,\”得分\“:0} ]“;

    ObjectMapper mapper=new ObjectMapper();
    ArrayNode arrayNode=(ArrayNode)mapper.readTree(inputJson);
    System.out.println(arrayNode.get(0).path("attributionText"));
    
  2. 使用Jackson fastxml api

    String inputJson =“[{\”textProns \“:[],\”sourceDictionary \“:\”ahd-legacy \“,\”exampleUses \“:[],\”relatedWords \“:[], \“labels \”:[],\“citations \”:[],\“word \”:\“car \”,\“partOfSpeech \”:\“noun \”,\“attributionText \”:\“来自TheAmericanHeman®英语词典,第4版\“,\”序列\“:\”0 \“,\”text \“:\”汽车。\“,\”得分\“:0} ]“;

    var i = 1;
    $('.button').click(function () {
        $('<input name="name' + (++i) + '" type="text"/><button class="remove">remove</button><br>').prependTo($(this).closest('div'));
    });
    
    $("div").on("click", ".remove",function () {
        $(this).prev("input").add($(this).next("br")).add($(this)).remove();
    });