D
D
Danil2021-03-14 18:04:11
JavaScript
Danil, 2021-03-14 18:04:11

How to parse pseudo JSON to js?

json
"a:3:{i:0;a:9:{s:13:"option_name_t";s:18:"Пенсионер";s:14:"option_price_t";s:3:"200";s:12:"option_qty_t";s:2:"10";s:12:"option_rsv_t";s:1:"0";s:20:"option_default_qty_t";s:1:"0";s:17:"option_qty_t_type";s:8:"inputbox";s:20:"option_sale_end_date";s:10:"2021-03-14";s:20:"option_sale_end_time";s:5:"00:00";s:22:"option_sale_end_date_t";s:16:"2021-03-14 00:00";}i:1;a:9:{s:13:"option_name_t";s:30:"Ребёнок (до 8 лет)";s:14:"option_price_t";s:3:"700";s:12:"option_qty_t";s:2:"10";s:12:"option_rsv_t";s:1:"0";s:20:"option_default_qty_t";s:1:"0";s:17:"option_qty_t_type";s:8:"inputbox";s:20:"option_sale_end_date";s:10:"2021-03-14";s:20:"option_sale_end_time";s:5:"00:00";s:22:"option_sale_end_date_t";s:16:"2021-03-14 00:00";}i:2;a:9:{s:13:"option_name_t";s:14:"Обычный";s:14:"option_price_t";s:4:"1500";s:12:"option_qty_t";s:2:"10";s:12:"option_rsv_t";s:1:"0";s:20:"option_default_qty_t";s:1:"0";s:17:"option_qty_t_type";s:8:"inputbox";s:20:"option_sale_end_date";s:10:"2021-03-14";s:20:"option_sale_end_time";s:5:"00:00";s:22:"option_sale_end_date_t";s:16:"2021-03-14 00:00";}}"


API sends such a json, how to parse it in order to get the Ticket Type (Senior, Child, Ordinary) and prices for them? Please help :(

Answer the question

In order to leave comments, you need to log in

7 answer(s)
M
mletov, 2021-03-14
@flabot

Depends on how often revisions and format changes are expected. If not often, then you can just mess with your parser with regular expressions, replace and split.
If there is access to API developers, then you can ask them what kind of format it is, alternative json. If they did not invent it themselves and it has some name, then in Google it will be possible to google the library for parsing it.
PS: Here's what Google suggests
https://stackoverflow.com/questions/29815871/what-...
https://stackoverflow.com/questions/14227388/unser...
https://locutus.io/php/var /unserialize/

R
Rsa97, 2021-03-14
@Rsa97

It looks like the native PHP serialize function .
There is no standard way to deserialize such data in JS, you need to write your own function or google the finished one.
Your example decodes as:

spoiler
[
  {
    ​​option_default_qty_t: "0",
​​    option_name_t: "Пенсионер"
​​    option_price_t: "200",
    option_qty_t: "10",
    option_qty_t_type: "inputbox",
​​    option_rsv_t: "0",
​​    option_sale_end_date: "2021-03-14",
​​    option_sale_end_date_t: "2021-03-14 00:00",
​​    option_sale_end_time: "00:00",
​​  }, {
​    option_default_qty_t: "0",
​​    option_name_t: "Ребёнок (до 8 лет)",
​​    option_price_t: "700",
​​    option_qty_t: "10",
​​    option_qty_t_type: "inputbox",
​​    option_rsv_t: "0",
​​    option_sale_end_date: "2021-03-14",
    ​​option_sale_end_date_t: "2021-03-14 00:00",
    ​​option_sale_end_time: "00:00",
​​  }, {
​​    option_default_qty_t: "0",
​​    option_name_t: "Обычный",
​​    option_price_t: "1500",
​​    option_qty_t: "10",
​​    option_qty_t_type: "inputbox",
​​    option_rsv_t: "0",
​​    option_sale_end_date: "2021-03-14",
​​    option_sale_end_date_t: "2021-03-14 00:00",
​​    option_sale_end_time: "00:00",
  }
]

E
Evgeny Shcherbakov, 2021-03-14
@Simply1993

JSON.parse ?

A
Aligatro, 2018-01-23
@jazzman7

It can also be done in html. On css via keyframe. On js through velocity for example (well, or write animation with pens). In general, there are a lot of options: a demo on jquery taking into account the length of the text , a tutorial on creating in pure css , information about the html tag .

Y
Yakov Vylegzhanin, 2018-01-23
@vylegzhanin

htmlbook.ru/html/marquee

A
Andrey Fedorov, 2018-01-23
@aliencash

Enjoy https://codepen.io/aliencash/pen/yprKBM?editors=1100

A
A person from Kazakhstan, 2018-01-23
@LenovoId

on keyframes - you can try!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question