Functions
parseJSON()
parseJSON<
T
>(text
,options
):T
解析 JSON
文本
Type Parameters
Type Parameter |
---|
T |
Parameters
Parameter | Type | Description |
---|---|---|
text | string | JSON 文本 |
options | ParseJSONOptions <T > | 配置项 |
Returns
T
Example
ts
// 错误或者值为空时设置 {}
parseJSON('{ a: 1 }', { onNil: {} }) // 简写默认值
parseJSON('{ a: 1 }', { onNil: () => ({}) }) // 函数返回默认值
// => {}
// 错误时设为 {}
parseJSON('{ a: 1 }', { onNil: (error) => error ? {} : null })
// => {}
// 值为空时设为 {}
parseJSON('null', { onNil: (error) => error ? null : {} })
// => {}
Interfaces
ParseJSONOptions<T>
Type Parameters
Type Parameter |
---|
T |