package com.yidian.shenghuoquan.bmanagercenter.utils

import android.content.Context
import android.content.res.AssetManager
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader

/**
 * JSON解析工具类
 */
object JsonUtils {

  //从文件中读取内容转成json字符串
  fun file2JsonStr(context: Context, fileName: String): String? {
    val stringBuilder = StringBuilder()
    try {
      val assetManager: AssetManager = context.assets
      val isr = InputStreamReader(assetManager.open(fileName))
      val bf = BufferedReader(isr)
      var line: String?
      while (bf.readLine().also { line = it } != null) {
        stringBuilder.append(line)
      }
      bf.close()
      isr.close()
      return stringBuilder.toString()
    } catch (e: IOException) {
      e.printStackTrace()
    }
    return null
  }

}
