13 lines
293 B
TypeScript
13 lines
293 B
TypeScript
/**
|
|
* 尝试从字符串中提取JSON对象
|
|
*/
|
|
export const getJsonFromString = (str: string) => {
|
|
try {
|
|
const jsonMatch = str.match(/```json\s*([\s\S]*?)\s*```/);
|
|
if (jsonMatch && jsonMatch[1]) {
|
|
return JSON.parse(jsonMatch[1]);
|
|
}
|
|
} catch (error) {}
|
|
return null;
|
|
};
|