Пример #1
0
        public static ApiResponse ParseJsonResponse(Stream stream)
        {
            using (var jsonReader = new JsonTextReader(new StreamReader(stream)))
            {
                var apiResponse = new ApiResponse();

                while (jsonReader.Read())
                {
                    if (jsonReader.TokenType == JsonToken.PropertyName)
                    {
                        switch ((string)jsonReader.Value)
                        {
                        case "statusCode":
                            apiResponse.StatusCode = jsonReader.ReadAsInt32() ?? 0;
                            break;

                        case "count":
                            apiResponse.Count = jsonReader.ReadAsInt32() ?? 0;
                            break;

                        case "response":
                            apiResponse.Response = jsonReader.GetInnerJson();
                            break;

                        case "error":
                            jsonReader.Read();
                            throw ParseError(jsonReader);

                        default:
                            jsonReader.Skip();
                            break;
                        }
                    }
                }

                return(apiResponse);
            }
        }