douzhao7014 2018-05-10 11:40
浏览 18

如果数据类型从字符串更改为布尔数据存储,则会引发错误

I am storing my struct values in google data store. Here is my struct:

type Appointment struct {
    ID                    string 
    Appointment Date      string 
    Start Time            string 
    End Time              string 
    Select Specialization string 
    Smoking Status        string
} 

I have stored some data using datastore, but later changed the data type from string to bool for the field "Smoking Status" then the data store is throwing an error:

{"error":{"message":"data store: cannot load field \"Smoking Status\" into a \"simplysthealth.Encounter\": type mismatch: string versus bool"}}

Is there any feasible solution for this?

  • 写回答

1条回答 默认 最新

  • dtmooir3395 2018-05-10 12:09
    关注
    package main
    
    // I have corrected all of your method names
    type Appointment struct {
            ID                   string
            AppointmentDate      string
            StartTime            string
            EndTime              string
            SelectSpecialization string
            SmokingStatus        string
    }
    
    type AllOldData struct {
            Data []Appointment
    }
    type FixedAppointment struct {
            ID                   string
            AppointmentDate      string
            StartTime            string
            EndTime              string
            SelectSpecialization string
            SmokingStatus        bool
    }
    
    type FixedData struct {
            Data []FixedAppointment
    }
    
    func TypeFixing() FixedData {
    
            var OldData AllOldData
            var NewData FixedData
    
            OldData = GetYourAllOldData()
    
            for i, v := range OldData.Data {
                    if v.SmokingStatus == "true" {
                            // other value exchanging
                            NewData.Data[i].SmokingStatus = true
                    } else {
                            // other value exchanging
                            NewData.Data[i].SmokingStatus = false
                    }
            }
    
            return NewData // Save the data in a new table or whatever you call it
    
    }
    
    func GetYourAllOldData() AllOldData {
            // A function that returns all old data
            return AllOldData{} // You must return return your all data
    }
    

    This is what you need to do it manually!

    评论

报告相同问题?

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序