Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

java - GSON - convert a string into a JsonArray

I am trying to convert a string into a JsonArray. So far I have tried to do the following:

Gson().toJson(string)

Gson().toJsonTree(string)

both throw an exception saying that the argument is not a JsonArray.

Here is the string, as you can see it is a JsonArray:

"[{"match":{"id":92757102,"tournament_id":3666234,"state":"open","player1_id":58602461,"player2_id":58602459,"player1_prereq_match_id":null,"player2_prereq_match_id":null,"player1_is_prereq_match_loser":false,"player2_is_prereq_match_loser":false,"winner_id":null,"loser_id":null,"started_at":"2017-07-17T19:10:07.588-04:00","created_at":"2017-07-17T19:10:07.476-04:00","updated_at":"2017-07-17T19:10:07.588-04:00","identifier":"A","has_attachment":false,"round":1,"player1_votes":null,"player2_votes":null,"group_id":null,"attachment_count":null,"scheduled_time":null,"location":null,"underway_at":null,"optional":false,"rushb_id":null,"completed_at":null,"suggested_play_order":1,"prerequisite_match_ids_csv":"","scores_csv":""}}]"
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Gson().fromJson(string, JsonArray::class.java)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...