启动Camunda流程遇SPIN-01004错误:无匹配数据格式检测到
Alright, let's tackle that SPIN-01004 error you're hitting. The root issue here is that Camunda's SPIN API isn't recognizing your service task's response as a valid JSON format—even though it looks like JSON, it's actually being treated as a plain string right now.
Let's break down what's going wrong and how to fix it:
Why You're Seeing the Error
Your service task returns an escaped JSON string: "{\"key\":\"value\"}". When you pass this directly to S(response), SPIN doesn't auto-detect it as JSON because it's wrapped in quotes (it's a string representation of JSON, not the parsed object itself). On top of that, your script is trying to access key1 but your actual JSON only has key—that's a mismatch that would cause another error even after fixing the format issue.
Step-by-Step Fix
Update your output parameter script to first parse the string into a proper JSON object, then access the correct key:
Option 1: Use SPIN's Built-in JSON Parsing
This leverages Camunda's SPIN API to convert the string to a JSON object before accessing properties:
<camunda:outputParameter name="Result"> <camunda:script scriptFormat="Javascript"> // Parse the string to JSON, then get the "key" property S(response).json().prop('key').value(); </camunda:script> </camunda:outputParameter>
Option 2: Use Native JavaScript JSON.parse
If you prefer plain JS, this works too:
<camunda:outputParameter name="Result"> <camunda:script scriptFormat="Javascript"> // Parse the string and directly access the "key" property JSON.parse(response).key; </camunda:script> </camunda:outputParameter>
Quick Checks to Avoid Future Issues
- Double-check your JSON keys: Make sure the property name in your script (
key) matches exactly what's in the response—JSON is case-sensitive! - Validate your response: Ensure the service task is returning a valid JSON string (no typos, missing brackets, etc.). You can test it with a basic JSON validator if you're unsure.
- Confirm SPIN is available: For older Camunda versions, ensure the SPIN module is deployed (most recent versions include it by default).
内容的提问来源于stack exchange,提问作者Albin Chandy

