3

I have big String (which is not converted JSON):

{
  "MyType" : "5",
  "creationTime" : "06/03/2021 11:14:37",
  "entityCompositeKey" : "3001v4",
  ...
}

which another thousand lines.

I am only interested in value which is in MyType, I don't care about other values.

JSONObject jsonObj = new JSONObject(view);
String chiupType = jsonObj.get("MyType").toString();

but it's way too slow. What is the fastest way to get only one value from String(JSON)?

Michu93
  • 5,058
  • 7
  • 47
  • 80

1 Answers1

5

In the implementation, the whole JSON string is processed directly after the constructor has been called. Thus, there is no possibility to read out only a single value.

  • I was even thinking of taking MyType from String without even parsing because it's always comes as first value but when external app will change it - I'm done ;/ I see that `String type = new JsonParser().parse(view).getAsJsonObject().get("MyType").getAsString();` is faster than `JSONObject`. Thanks @Sapphirex! – Michu93 Jun 10 '22 at 11:25
  • I would expect this argument to be accompanied with a link to the specification to proof it. Still gave an upvote since it gives a new lead to research. – Omnibyte Jun 10 '22 at 15:00