xugenyuan

fix |> 空串解析json报错

Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
@@ -13,6 +13,7 @@ import { BusinessError } from '@kit.BasicServicesKit'; @@ -13,6 +13,7 @@ import { BusinessError } from '@kit.BasicServicesKit';
13 import { BottomNavigationComponent } from './view/BottomNavigationComponent'; 13 import { BottomNavigationComponent } from './view/BottomNavigationComponent';
14 import LaunchDataModel from './viewModel/LaunchDataModel'; 14 import LaunchDataModel from './viewModel/LaunchDataModel';
15 import { LaunchPageModel } from './viewModel/LaunchPageModel'; 15 import { LaunchPageModel } from './viewModel/LaunchPageModel';
  16 +import { JSON } from '@kit.ArkTS';
16 17
17 const TAG = 'MainPage'; 18 const TAG = 'MainPage';
18 19
@@ -46,14 +47,19 @@ struct MainPage { @@ -46,14 +47,19 @@ struct MainPage {
46 LogoutViewModel.clearLoginInfo() 47 LogoutViewModel.clearLoginInfo()
47 }) 48 })
48 49
49 - let dataModelStr : string = SPHelper.default.getSync(SpConstants.APP_MOURNS_INFO_DATA_MODEL,'') as string  
50 - let dataModel : LaunchDataModel = JSON.parse(dataModelStr)  
51 - // console.log(dataModelStr)  
52 - // 处理国殇模式数据  
53 - let mourns: mournsInfoModel = dataModel.mourns as mournsInfoModel  
54 let GrayManage = new GrayManageModel() 50 let GrayManage = new GrayManageModel()
55 - GrayManage.setMourning(mourns)  
56 - AppStorage.setOrCreate('GrayManage', GrayManage) 51 + let dataModelStr : string = SPHelper.default.getSync(SpConstants.APP_MOURNS_INFO_DATA_MODEL,'') as string
  52 + try {
  53 + if (dataModelStr && dataModelStr.length > 0) {
  54 + let dataModel : LaunchDataModel = JSON.parse(dataModelStr) as LaunchDataModel
  55 + // 处理国殇模式数据
  56 + let mourns: mournsInfoModel = dataModel.mourns as mournsInfoModel
  57 + GrayManage.setMourning(mourns)
  58 + }
  59 + AppStorage.setOrCreate('GrayManage', GrayManage)
  60 + } catch (e) {
  61 + Logger.error(TAG, `Unexpected Text in JSON ??` + JSON.stringify(e) +" " + dataModelStr);
  62 + }
57 } 63 }
58 64
59 pageTransition() { 65 pageTransition() {