You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
406 B
22 lines
406 B
5 months ago
|
var isPlainObject = require('./isPlainObject')
|
||
|
var isString = require('./isString')
|
||
|
|
||
|
/**
|
||
|
* 字符串转JSON
|
||
|
*
|
||
|
* @param {String} str 字符串
|
||
|
* @return {Object} 返回转换后对象
|
||
|
*/
|
||
|
function toStringJSON (str) {
|
||
|
if (isPlainObject(str)) {
|
||
|
return str
|
||
|
} else if (isString(str)) {
|
||
|
try {
|
||
|
return JSON.parse(str)
|
||
|
} catch (e) {}
|
||
|
}
|
||
|
return {}
|
||
|
}
|
||
|
|
||
|
module.exports = toStringJSON
|