# 调试 JSON 读取 $raw = Get-Content 'D:\Softwares\phpstudy_pro\WWW\fenleixinxi\tmp_img\prompt_map.json' -Raw -Encoding UTF8 Write-Host "Raw length: $($raw.Length)" Write-Host "First 100 chars: $($raw.Substring(0, [Math]::Min(100, $raw.Length)))" try { $json = $raw | ConvertFrom-Json Write-Host "Parsed count: $($json.Count)" } catch { Write-Host "ConvertFrom-Json failed: $_" } # 手动解析 $items = @() $current = $null $inPrompt = $false $sb = New-Object System.Text.StringBuilder $lines = Get-Content 'D:\Softwares\phpstudy_pro\WWW\fenleixinxi\tmp_img\prompt_map.json' -Encoding UTF8 Write-Host "Line count: $($lines.Count)" foreach ($line in $lines) { # 简单的 regex 匹配 if ($line -match '"id"\s*:\s*"(\d+)"') { if ($current) { $items += $current } $current = [PSCustomObject]@{ id = $Matches[1]; name = ''; kind = ''; path = ''; prompt = '' } } if ($current -and $line -match '"name"\s*:\s*"([^"]*)"') { $current.name = $Matches[1] } if ($current -and $line -match '"kind"\s*:\s*"([^"]*)"') { $current.kind = $Matches[1] } if ($current -and $line -match '"path"\s*:\s*"([^"]*)"') { $current.path = $Matches[1] -replace '\\/', '/' } if ($current -and $line -match '"prompt"\s*:\s*"(.*)') { $current.prompt = $Matches[1] -replace '"\s*,?\s*$', '' } } if ($current) { $items += $current } Write-Host "Regex-parsed count: $($items.Count)" # 转换 path $mcpItems = foreach ($item in $items) { $mcpPath = $item.path -replace '\\', '/' $mcpPath = $mcpPath -replace '\.jpg$', '' [PSCustomObject]@{ id = $item.id name = $item.name mcp_path = $mcpPath prompt = $item.prompt } } $mcpItems | ConvertTo-Json -Depth 3 | Set-Content 'D:\Softwares\phpstudy_pro\WWW\fenleixinxi\tmp_img\mcp_items.json' Write-Host "Saved $($mcpItems.Count) items to mcp_items.json"