Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

android - How to convert a Json String/Data to a Java Class?

I'm new in Android and programming as well. I would like to build an Android app with user login and User Location tracer. What's the easiest way to convert a Json String to Java Class?

My Json String:

Json String

question from:https://stackoverflow.com/questions/65889960/how-to-convert-a-json-string-data-to-a-java-class

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

1 Answer

0 votes
by (71.8m points)

You can use ObjectMapper

import com.fasterxml.jackson.databind.ObjectMapper;

public class YourClassDao {

private ObjectMapper objectMapper = new ObjectMapper();

  public YourClass load(String json) throws IOException {
    return objectMapper.readValue(
        json, YourClass.class);
  }

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...