我需要将个人资料图片上传到个人资料。我需要获取ID,以便将图片上传到正确的个人资料。 API的响应是Gunzip对象。
.then(resp => JSON.parse(resp))。then(data => {console.log(data.Gunzip.read(5)})
我已经尝试过,但是遇到了一个错误:(node:16100)UnhandledPromiseRejectionWarning:SyntaxError:JSON中位置1上的意外令牌o
public class LogLevelConverter : JsonConverter<LogLevel>
{
public override LogLevel ReadJson(JsonReader reader, Type objectType, LogLevel existingValue, bool hasExistingValue, JsonSerializer serializer)
{
switch (reader.MoveToContentAndAssert().TokenType)
{
case JsonToken.Null:
return null;
case JsonToken.String:
return LogLevel.FromString((string)reader.Value);
default:
throw new JsonSerializationException(string.Format("Unknown token {0}", reader.TokenType));
}
}
public override void WriteJson(JsonWriter writer, LogLevel value, JsonSerializer serializer)
{
var logLevel = (LogLevel)value;
writer.WriteValue(logLevel.Name);
}
}
public static partial class JsonExtensions
{
public static JsonReader MoveToContentAndAssert(this JsonReader reader)
{
if (reader == null)
throw new ArgumentNullException();
if (reader.TokenType == JsonToken.None) // Skip past beginning of stream.
reader.ReadAndAssert();
while (reader.TokenType == JsonToken.Comment) // Skip past comments.
reader.ReadAndAssert();
return reader;
}
public static JsonReader ReadAndAssert(this JsonReader reader)
{
if (reader == null)
throw new ArgumentNullException();
if (!reader.Read())
throw new JsonReaderException("Unexpected end of JSON stream.");
return reader;
}
}
使用此代码,我得到的是压缩对象而不是对象,因此我看不到所需的ID。