I'm writing a server that need to parse JSON strings uploaded by clients. Currently I'm using Play JSON lib. For example:
import play.api.libs.json._
def parseJSON(jsonString: String) = {
val jsv = Json.parse(jsonString)
jsv
}
Considering a client uploaded a JOSN string of {"key1": 1}
. After the server received the entire string, just simple invoke the parseJSON
method, everything will be done.
However, if a client uploaded TWO JSON strings, {"key2": 2}
and {"key3": 3}
, and due to the bad network, these two JSON strings reach the server at the same time. The server will get a long string of {"key2": 2}{"key3": 3}
(The server can not know it contains two JSON strings before parsing). if I invoke the parseJSON
method and pass the entire string, only the first JSON value {"key2": 2}
will be returned. The second one {"key3": 3}
will be ignored.
So, how can I parse the second JSON string? Is there a way to know how many Chars are used when parsing the first JSON string?