Giter Club home page Giter Club logo

Comments (1)

afkT avatar afkT commented on May 21, 2024

这个不方便添加到 DevApp 库中,因为会依赖 Gson 且导致别人项目版本不一致,但是我有专门的 kotlin 库里面实现了。

// DevEngine - 第三方框架解耦、一键替换第三方库、同类库多 Engine 组件化混合使用
implementation 'io.github.afkt:DevEngine:1.0.8'

如何使用 Gson 可查看 json.kt 以下为使用示例:

// 初始化只需调用
DevEngine.completeInitialize(context)

// 假设存在 User 实体类
val user = User()
// 转换为 JSON 字符串
val json = user.toJson()
// 映射为实体类
val user1 = json.fromJson(
    classOfT = User::class.java
)

// 上面是最简单常见的使用,下面还有其他方法

// 转换为 JSON 字符串并进行格式化缩进
val json = user.toJsonIndent()
// 判断字符串是否 JSON 格式
json.isJSON()
// 判断字符串是否 JSON Object 格式
json.isJSONObject()
// 判断字符串是否 JSON Array 格式
json.isJSONArray()

只要调用初始化 DevEngine.completeInitialize(context) 方法,无需考虑内部实现,默认使用 Gson 作为 JSON Engine 进行处理了。

from devutils.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.