не могу распарсить | I can't parse it - Forum

Forum Navigation
You need to log in to create posts and topics.

не могу распарсить | I can't parse it

запрос в php, работает, возвращает ответ.
PHP request, works, returns response.

// получить плагин
$sqlAlias[1]="selectPlugin";
$sqlQuerys[1]="SELECT plugin.name, plugin.description, json_group_array(json_object('name', pluginLink.name, 'link', pluginLink.link)) AS links  FROM plugin INNER JOIN pluginLink ON pluginLink.id_plugin = plugin.id WHERE plugin.name = ? ";
$sqlMaxUserLevel[1]=-1;

Попытка получить значение
Trying to get the value

CreateEmptyArray [mypluginname]
SetVar [mypluginname] [data]
BeginJS
  const jsonString = JSON.stringify($App.mypluginname);
  console.log(jsonString);
EndJS
JSAlert "[mypluginname.links(1).name]"

Результат консоли
Console result

[{"name":"pvvJSChart","description":"pvvJSСhart — это мощная и простая в использовании библиотека JavaScript для создания интерактивных графиков и диаграмм на веб-страницах основанная на библиотеке Chart.js. Она особенно привлекательна для разработчиков благодаря своей легкости и гибкости, а также множеству возможностей, которые позволяют визуализировать данные.","links":"[{\"name\":\"Download | Скачать .rar\",\"link\":\"https://fileworld.pavlenkovv.ru/components/mvd/pvvJSChart/pvvJSСhart.rar\"},{\"name\":\"Download | Скачать .rar\",\"link\":\"https://fileworld.pavlenkovv.ru/components/mvd/pvvJSChart/pvvJSСhart.zip\"}]"}]
main.js:71 Uncaught TypeError: Cannot read properties of undefined (reading '1')

 

@lolo Your console error:

Uncaught TypeError: Cannot read properties of undefined (reading '1')

means this line fails:

JSAlert "[mypluginname.links(1).name]"

Why? Two reasons:

  1. Indexes in VisualNEO Web arrays start at 0, not 1.

    The first item in an object structure is zero.

  2. links is still a JSON string, not a parsed object.
    You must use ParseJSON before trying to access its items.

Please check the included sample apps and VisualNEO Youtube Channel for more information.

@luishp
Я решил это так:
I solved it this way:

CreateEmptyObject [jsonData]
CreateEmptyObject [jsonDataLinks]
SetVar [jsonData] [data]
ParseJSON "[jsonData(0).links]" [jsonDataLinks]

SetVar [pluginName] [jsonData(0).name]
SetVar [pluginDescription] [jsonData(0).description]
SetVar [PluginLinkOne] [jsonDataLinks(0).name]
SetVar [PluginLinkTwo] [jsonDataLinks(1).name]
SetVar [PluginLinkNameOne] [jsonDataLinks(0).link]
SetVar [PluginLinkNameTwo] [jsonDataLinks(1).link]

luishp has reacted to this post.
luishp