Baseencoded 문자열에서 키-값 쌍을 구문 분석하는 방법#eg11

王林
풀어 주다: 2024-07-18 06:58:30
원래의
350명이 탐색했습니다.

We have a Base64-encoded string as follows:

eyJhIjo2MywiYyI6Mjk4LCJuIjoxLCJzIjoxLCJlIjo0MCwicCI6NH0=

And are trying to parse the transcoded JSON string ({"a":63,"c":298,"n":1,"s":1,"e":40,"p":4}) as a table. Below is the desired result:

Image description
SQL written in MySQL:

SELECT

            JSON_EXTRACT(CONVERT(FROM_BASE64('eyJhIjo2MywiYyI6Mjk4LCJuIjoxLCJzIjoxLCJlIjo0MCwicCI6NH0=')

                        USING utf8),

            '$."a"') a,

            JSON_EXTRACT(CONVERT(FROM_BASE64('eyJhIjo2MywiYyI6Mjk4LCJuIjoxLCJzIjoxLCJlIjo0MCwicCI6NH0=')

                        USING utf8),

            '$."c"') c,

            JSON_EXTRACT(CONVERT(FROM_BASE64('eyJhIjo2MywiYyI6Mjk4LCJuIjoxLCJzIjoxLCJlIjo0MCwicCI6NH0=')

                        USING utf8),

            '$."n"') n,

            JSON_EXTRACT(CONVERT(FROM_BASE64('eyJhIjo2MywiYyI6Mjk4LCJuIjoxLCJzIjoxLCJlIjo0MCwicCI6NH0=')

                        USING utf8),

            '$."s"') s,

            JSON_EXTRACT(CONVERT(FROM_BASE64('eyJhIjo2MywiYyI6Mjk4LCJuIjoxLCJzIjoxLCJlIjo0MCwicCI6NH0=')

                        USING utf8),

            '$."e"') e,

            JSON_EXTRACT(CONVERT(FROM_BASE64('eyJhIjo2MywiYyI6Mjk4LCJuIjoxLCJzIjoxLCJlIjo0MCwicCI6NH0=')

                        USING utf8),

            '$."p"') p
로그인 후 복사

There is nothing hard about it. We only need to convert the Base64-encoded strings into JSON strings, then parse JSON into a table according to K-V pairs. SQL coding is complicated, particularly when the number of columns in the result table is unknown.

 

It is easy to code it in the open-source esProc SPL:

Suppose the value of parameter arg1 is:

eyJhIjo2MywiYyI6Mjk4LCJuIjoxLCJzIjoxLCJlIjo0MCwicCI6NH0=

Image description
As the open-source, professional structured data computation language, SPL is convenient in handling various data sources, including JSON.

위 내용은 Baseencoded 문자열에서 키-값 쌍을 구문 분석하는 방법#eg11의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

원천:dev.to
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!