fix |> 空串解析json报错
Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
Showing
1 changed file
with
9 additions
and
3 deletions
| @@ -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 | ||
| 50 | + let GrayManage = new GrayManageModel() | ||
| 49 | let dataModelStr : string = SPHelper.default.getSync(SpConstants.APP_MOURNS_INFO_DATA_MODEL,'') as string | 51 | 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 | + try { |
| 53 | + if (dataModelStr && dataModelStr.length > 0) { | ||
| 54 | + let dataModel : LaunchDataModel = JSON.parse(dataModelStr) as LaunchDataModel | ||
| 52 | // 处理国殇模式数据 | 55 | // 处理国殇模式数据 |
| 53 | let mourns: mournsInfoModel = dataModel.mourns as mournsInfoModel | 56 | let mourns: mournsInfoModel = dataModel.mourns as mournsInfoModel |
| 54 | - let GrayManage = new GrayManageModel() | ||
| 55 | GrayManage.setMourning(mourns) | 57 | GrayManage.setMourning(mourns) |
| 58 | + } | ||
| 56 | AppStorage.setOrCreate('GrayManage', GrayManage) | 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() { |
-
Please register or login to post a comment