gpt4 book ai didi

javascript - json数据解析问题

转载 作者:行者123 更新时间:2023-12-03 03:08:07 24 4
gpt4 key购买 nike

我有以下数据:

{
"Result": "{\"Plot\":{\"Series\":[{\"color\":\"green\",\"title\":\"Temperature Gradient\",\"x_unit\":\"Temperature (°F)\",\"y_unit\":\"Depth (ft)\",\"dashStyle\":\"Solid\",\"lineType\":\"spline\",\"xAxisOnTop\":true,\"x_values\":\"80,90.78,101.56,112.35,123.13,133.91,144.69,155.47,166.26,177.04,199.96,210.63,220\",\"y_values\":\"0,-404.6,-809.2,-1213.8,-1618.4,-2023,-2427.6,-2832.2,-3236.8,-3641.4,-4046,-4502,-4825\"}]},\"OperatingTagResult\":null}",
"StatusCode": 200
}

我想要获得两个新变量。

  1. {\"绘图\":{\"系列\":[{\"颜色\":\"绿色\",\"标题\":\"温度梯度\",\"x_unit\":\"温度 (°F)\",\"y_unit\":\"深度 (ft)\",\"dashStyle\":\"Solid\",\"lineType\":\“样条线\”,\“xAxisOnTop\”:true,\“x_values\”:\“80,90.78,101.56,112.35,123.13,133.91,144.69,155.47,166.26,177.04,199.96,210.63,220\”,\"y_values\":\"0,-404.6,-809.2,-1213.8,-1618.4,-2023,-2427.6,-2832.2,-3236.8,-3641.4,-4046,-4502,-4825\"}]},\"OperatingTagResult\":null}

  2. “StatusCode”只需 200

我该如何实现这个?

使用 json 解析时出现下一个错误:

Uncaught SyntaxError: Unexpected token o in JSON at position 1

最佳答案

只需定义一个变量并使用点符号即可访问“Result”和“StatusCode”属性:

var income = {"Result":"{\"Plot\":{\"Series\":[{\"color\":\"green\",\"title\":\"Temperature Gradient\",\"x_unit\":\"Temperature (°F)\",\"y_unit\":\"Depth (ft)\",\"dashStyle\":\"Solid\",\"lineType\":\"spline\",\"xAxisOnTop\":true,\"x_values\":\"80,90.78,101.56,112.35,123.13,133.91,144.69,155.47,166.26,177.04,199.96,210.63,220\",\"y_values\":\"0,-404.6,-809.2,-1213.8,-1618.4,-2023,-2427.6,-2832.2,-3236.8,-3641.4,-4046,-4502,-4825\"}]},\"OperatingTagResult\":null}","StatusCode":200}

var result = income.Result; // {"Plot":{"Series":[{"color":"green", ...
var status = income.StatusCode; // 200

关于javascript - json数据解析问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47078363/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com