如何在 wordpress 中解码 javascript 中的 Json 数据
How to decode Json data in javascript in wordpress
我遇到了与 JSON 有关的问题。我有以下代码:
[
[
{
"id": "100",
"course_id": "92",
"skills": "2",
"from_time": "1:00am",
"to_time": "5:30am",
"class_type": "1",
"no_weeks": "5",
"cid": "16",
"mon": "1",
"tue": "1",
"wed": "1",
"thu": "0",
"fri": "0",
"sat": "0",
"sun": "0",
"intake": "30",
"address": "raviwar peth",
"payment": "3000",
"payment_type": "per class",
"payment_policy": "before lessons(monthly)",
"cancellation_policy": "dfs dfd sfds fsdf sd",
"created_on": "2016-01-13 06:17:08"
}
]
]
我无法将此 JSON 数据解码为 JavaScript。
假设此数据位于名为 data
的变量中。
要在 Javascript 中解析它,请使用代码。
JSON.parse(data)
嗨,我已经解码了你的 json data.Please 检查 DEMO
json 数据附加 0 可能是问题。
请检查您是否添加了exit or die()
?如果不是请在returnjson后添加ajaxphp文件中的数据。
先创建一个var text = '{"id":100,"count":1}'
.
之后使用JavaScriptfunction JSON.parse(text)
用于将 JSON 文本转换为 JavaScript 对象:
obj = JSON.parse(text);
alert (obj.count);
我遇到了与 JSON 有关的问题。我有以下代码:
[
[
{
"id": "100",
"course_id": "92",
"skills": "2",
"from_time": "1:00am",
"to_time": "5:30am",
"class_type": "1",
"no_weeks": "5",
"cid": "16",
"mon": "1",
"tue": "1",
"wed": "1",
"thu": "0",
"fri": "0",
"sat": "0",
"sun": "0",
"intake": "30",
"address": "raviwar peth",
"payment": "3000",
"payment_type": "per class",
"payment_policy": "before lessons(monthly)",
"cancellation_policy": "dfs dfd sfds fsdf sd",
"created_on": "2016-01-13 06:17:08"
}
]
]
我无法将此 JSON 数据解码为 JavaScript。
假设此数据位于名为 data
的变量中。
要在 Javascript 中解析它,请使用代码。
JSON.parse(data)
嗨,我已经解码了你的 json data.Please 检查 DEMO
json 数据附加 0 可能是问题。
请检查您是否添加了exit or die()
?如果不是请在returnjson后添加ajaxphp文件中的数据。
先创建一个var text = '{"id":100,"count":1}'
.
之后使用JavaScriptfunction JSON.parse(text)
用于将 JSON 文本转换为 JavaScript 对象:
obj = JSON.parse(text);
alert (obj.count);