Efficient parsing of first four elements of large JSON arrays

后端 未结 1 374
傲寒
傲寒 2021-01-25 01:29

I am using Jackson to parse JSON from a json inputStream which looks like following:

[
      [ 36,
        100,
        \"The 3n +          


        
相关标签:
1条回答
  • 2021-01-25 01:39

    This is for Jackson

    Follow this tutorial.

    Judicious use of jasonParser.nextToken() should help you.

    while (jasonParser.nextToken() != JsonToken.END_ARRAY) { // might be JsonToken.START_ARRAY?
    

    The pseudo-code is

    1. find next array
      1. read values
      2. skip other values
      3. skip next end token

    This is for gson. Take a look at this tutorial. Consider following second example from the tutorial.

    Judicious use of reader.begin* reader.end* and reader.skipValue should do the job for you.

    And here is the documentation for JsonReader

    0 讨论(0)
提交回复
热议问题