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
202 views
in Technique[技术] by (71.8m points)

android - How can I read Uri , double values from json file in kotlin?

I have a Car class and it has brand name , price and uri for image. I have a recyler view in my main activity. I can store my brand name and my other strings in json file and show all strings in recyler view but how can I store and read uri and double in json file?

NewCar

        var newCar = Car()



        newCar.brandName = brandName.text.toString()
        newCar.modelName = modelName.text.toString()

        newCar.price = price.text.toString().toDouble()

        newCar.fuelType = fuelType.text.toString()
        newCar.gearType = gearType.text.toString()
        newCar.km = kilometer.text.toString().toDouble()
        newCar.image = imageUri


        val callingActivity = activity as MainActivity?
        callingActivity!!.createNewCar(newCar)

JSON Constructor

@Throws(JSONException::class)
constructor(jo: JSONObject) {

    modelName = jo.getString(JSON_MODELNAME)
    brandName = jo.getString(JSON_BRANDNAME)
    fuelType = jo.getString(JSON_FUELTYPE)
    km = jo.getDouble(JSON_KM)
    price = jo.getDouble(JSON_PRICE)
    color = jo.getString(JSON_COLOR)
   
    gearType = jo.getString(JSON_GEARTYPE)
    
    image = jo.get // what should I write here

}

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

1 Reply

0 votes
by (71.8m points)

Store uri as String:

newCar.image = imageUri.toString()

image = jo.getString(xxx)

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

...