{"record":{"id":"760605a510ea41fa","repo":"XINCGer/Unity3DTraining","slug":"unsupported-json-token-type","errorCode":null,"errorMessage":"Unsupported JSON token type ","messagePattern":"Unsupported JSON token type ","errorType":"validation","errorClass":"InvalidProtocolBufferException","httpStatus":null,"severity":"error","filePath":"NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs","lineNumber":365,"sourceCode":"            {\n                case JsonToken.TokenType.True:\n                case JsonToken.TokenType.False:\n                    if (fieldType == FieldType.Bool)\n                    {\n                        return token.Type == JsonToken.TokenType.True;\n                    }\n                    // Fall through to \"we don't support this type for this case\"; could duplicate the behaviour of the default\n                    // case instead, but this way we'd only need to change one place.\n                    goto default;\n                case JsonToken.TokenType.StringValue:\n                    return ParseSingleStringValue(field, token.StringValue);\n                // Note: not passing the number value itself here, as we may end up storing the string value in the token too.\n                case JsonToken.TokenType.Number:\n                    return ParseSingleNumberValue(field, token);\n                case JsonToken.TokenType.Null:\n                    throw new NotImplementedException(\"Haven't worked out what to do for null yet\");\n                default:\n                    throw new InvalidProtocolBufferException(\"Unsupported JSON token type \" + token.Type + \" for field type \" + fieldType);\n            }\n        }\n\n        /// <summary>\n        /// Parses <paramref name=\"json\"/> into a new message.\n        /// </summary>\n        /// <typeparam name=\"T\">The type of message to create.</typeparam>\n        /// <param name=\"json\">The JSON to parse.</param>\n        /// <exception cref=\"InvalidJsonException\">The JSON does not comply with RFC 7159</exception>\n        /// <exception cref=\"InvalidProtocolBufferException\">The JSON does not represent a Protocol Buffers message correctly</exception>\n        public T Parse<T>(string json) where T : IMessage, new()\n        {\n            ProtoPreconditions.CheckNotNull(json, \"json\");\n            return Parse<T>(new StringReader(json));\n        }\n\n        /// <summary>\n        /// Parses JSON read from <paramref name=\"jsonReader\"/> into a new message.","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/XINCGer/Unity3DTraining/blob/016f98412ea5e11756b286736f479b66ab6216d5/NetWorkAndResources/Socket_Protobuff/Assets/Plugins/Google.Protobuf/JsonParser.cs#L347-L383","documentation":"ParseSingleValue's switch exhausted all expected JSON token types (name/value kinds it supports plus Null); the default case rejects any other JsonToken.TokenType with this InvalidProtocolBufferException, appending the token type and target field type. It fires when a scalar/single-value parse position receives a token the parser does not associate with a valid single value — most commonly a structural token.","triggerScenarios":"A field expecting a scalar receives a structural JSON token not routed elsewhere — e.g. an unmatched StartObject/StartArray token reaching a scalar field during malformed nesting, or a parser-internal token kind appearing where a value is expected.","commonSituations":"Malformed JSON where an array value lands on a scalar field path through MergeRepeatedField edge cases; custom JsonTokenizer implementations emitting unexpected token types; truncated or corrupted JSON streams producing dangling structural tokens.","solutions":["Validate the JSON payload shape against the proto schema: scalar fields must receive string/number/boolean, repeated fields must receive arrays, message fields must receive objects.","Fix mismatched nesting in the JSON (unbalanced braces/brackets) before parsing.","If using a custom JsonTokenizer, ensure it only emits standard JsonToken.TokenType values for valid positions.","Catch InvalidProtocolBufferException and surface the token type and field type mentioned in the message to pinpoint the payload defect."],"exampleFix":"// before: array where a scalar is expected\n{\"retries\": [3]}\n\n// after\n{\"retries\": 3}","handlingStrategy":"type-guard","validationCode":"// Scalar fields must receive string/number/boolean tokens, not objects or arrays\nfunction isScalar(v) { return ['string', 'number', 'boolean'].includes(typeof v) || v === null; }","typeGuard":"function isScalar(v) { return v === null || typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean'; }","tryCatchPattern":"try { var msg = JsonParser.Default.Parse<T>(json); }\ncatch (InvalidProtocolBufferException ex) when (ex.Message.StartsWith(\"Unsupported JSON token type\")) { /* surface token type + field type from message to caller */ }","preventionTips":["Generate JSON from a typed schema so scalars never become objects/arrays","Validate payloads against the proto-derived schema before parsing","Fix JSON nesting errors (unbalanced braces) at the source"],"tags":["protobuf","json-parsing","token-type","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"016f98412ea5e11756b286736f479b66ab6216d5","analyzedAt":"2026-09-12T01:08:58.711Z","contentChangedAt":"2026-09-12T01:08:58.711Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}