这样的json数据如何解析
这样的json数据怎么解析
- JScript code
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
var myTransActionsData = {
'data': [
{
'stock_name': "\u7231\u4ed5\u8fbe",
'stock_symbol': '002403',
'transaction_time': '2010-09-10 09:32:31',
'flag': 'sell',
'price': '17.52',
'amount': '39900',
'display': 'black'
},
{
'stock_name': "\u7231\u4ed5\u8fbe",
'stock_symbol': '002403',
'transaction_time': '2010-09-09 13:05:16',
'flag': 'buy',
'price': '17.65',
'amount': '39900',
'display': 'black'
},
{
'stock_name': "\u987a\u7f51\u79d1\u6280",
'stock_symbol': '300113',
'transaction_time': '2010-09-07 10:53:08',
'flag': 'sell',
'price': '84.98',
'amount': '8300',
'display': 'black'
},
{
'stock_name': "\u987a\u7f51\u79d1\u6280",
'stock_symbol': '300113',
'transaction_time': '2010-09-06 13:01:47',
'flag': 'buy',
'price': '79.80',
'amount': '8300',
'display': 'black'
},
{
'stock_name': "\u987a\u7f51\u79d1\u6280",
'stock_symbol': '300113',
'transaction_time': '2010-09-03 09:31:08',
'flag': 'sell',
'price': '78.87',
'amount': '8300',
'display': 'black'
},
{
'stock_name': "\u987a\u7f51\u79d1\u6280",
'stock_symbol': '300113',
'transaction_time': '2010-09-02 09:37:44',
'flag': 'buy',
'price': '75.54',
'amount': '8300',
'display': 'black'
},
{
'stock_name': "\u6d77\u683c\u901a\u4fe1",
'stock_symbol': '002465',
'transaction_time': '2010-09-02 09:30:27',
'flag': 'sell',
'price': '49.10',
'amount': '13000',
'display': 'black'
},
{
'stock_name': "\u6d77\u683c\u901a\u4fe1",
'stock_symbol': '002465',
'transaction_time': '2010-09-01 14:01:05',
'flag': 'buy',
'price': '49.54',
'amount': '13000',
'display': 'black'
},
{
'stock_name': "\u987a\u7f51\u79d1\u6280",
'stock_symbol': '300113',
'transaction_time': '2010-09-01 13:46:08',
'flag': 'sell',
'price': '72.98',
'amount': '8800',
'display': 'black'
},
{
'stock_name': "\u987a\u7f51\u79d1\u6280",
'stock_symbol': '300113',
'transaction_time': '2010-08-27 09:34:52',
'flag': 'buy',
'price': '64.16',
'amount': '8800',
'display': 'black'
},
{
'stock_name': "\u91d1\u53d1\u79d1\u6280",
'stock_symbol': '600143',
'transaction_time': '2010-08-27 09:30:59',
'flag': 'sell',
'price': '10.99',
'amount': '52100',
'display': 'black'
},
{
'stock_name': "\u91d1\u53d1\u79d1\u6280",
'stock_symbol': '600143',
'transaction_time': '2010-08-26 13:59:58',
'flag': 'buy',
'price': '10.92',
'amount': '52100',
'display': 'black'
},
{
'stock_name': "\u534e\u4ec1\u836f\u4e1a",
'stock_symbol': '300110',
'transaction_time': '2010-08-26 10:35:36',
'flag': 'sell',
'price': '22.57',
'amount': '25300',
'display': 'black'
},
{
'stock_name': "\u534e\u4ec1\u836f\u4e1a",
'stock_symbol': '300110',
'transaction_time': '2010-08-25 09:31:05',
'flag': 'buy',
'price': '23.88',
'amount': '25300',
'display': 'black'
},
{
'stock_name': "\u90d1\u7164\u673a",
'stock_symbol': '601717',
'transaction_time': '2010-08-24 10:41:38',
'flag': 'sell',
'price': '32.63',
'amount': '18400',
'display': 'black'
}
],
'count' : 541,
pagesize: 15,
'status' : '1000'
}
myTransActionsData['pages'] = Math.ceil(parseInt(myTransActionsData['count'])/parseInt(myTransActionsData['pagesize']))
我用这种方法
$str = file_get_contents($url);
$data = json_decode($str);
得不到数据。
我主要是想遍历data里面的数据,得到里面的值。
------解决方案--------------------
主要是后面的 【'count' : 541, pagesize: 15,】格式不对,要处理一下
- PHP code
<?php $str=<<<JSON
{ 'data': [ { 'stock_name': "\u7231\u4ed5\u8fbe", 'stock_symbol': '002403', 'transaction_time': '2010-09-10 09:32:31', 'flag': 'sell', 'price': '17.52', 'amount': '39900', 'display': 'black' }, { 'stock_name': "\u7231\u4ed5\u8fbe", 'stock_symbol': '002403', 'transaction_time': '2010-09-09 13:05:16', 'flag': 'buy', 'price': '17.65', 'amount': '39900', 'display': 'black' }, { 'stock_name': "\u987a\u7f51\u79d1\u6280", 'stock_symbol': '300113', 'transaction_time': '2010-09-07 10:53:08', 'flag': 'sell', 'price': '84.98', 'amount': '8300', 'display': 'black' }, { 'stock_name': "\u987a\u7f51\u79d1\u6280", 'stock_symbol': '300113', 'transaction_time': '2010-09-06 13:01:47', 'flag': 'buy', 'price': '79.80', 'amount': '8300', 'display': 'black' }, { 'stock_name': "\u987a\u7f51\u79d1\u6280", 'stock_symbol': '300113', 'transaction_time': '2010-09-03 09:31:08', 'flag': 'sell', 'price': '78.87', 'amount': '8300', 'display': 'black' }, { 'stock_name': "\u987a\u7f51\u79d1\u6280", 'stock_symbol': '300113', 'transaction_time': '2010-09-02 09:37:44', 'flag': 'buy', 'price': '75.54', 'amount': '8300', 'display': 'black' }, { 'stock_name': "\u6d77\u683c\u901a\u4fe1", 'stock_symbol': '002465', 'transaction_time': '2010-09-02 09:30:27', 'flag': 'sell', 'price': '49.10', 'amount': '13000', 'display': 'black' }, { 'stock_name': "\u6d77\u683c\u901a\u4fe1", 'stock_symbol': '002465', 'transaction_time': '2010-09-01 14:01:05', 'flag': 'buy', 'price': '49.54', 'amount': '13000', 'display': 'black' }, { 'stock_name': "\u987a\u7f51\u79d1\u6280", 'stock_symbol': '300113', 'transaction_time': '2010-09-01 13:46:08', 'flag': 'sell', 'price': '72.98', 'amount': '8800', 'display': 'black' }, { 'stock_name': "\u987a\u7f51\u79d1\u6280", 'stock_symbol': '300113', 'transaction_time': '2010-08-27 09:34:52', 'flag': 'buy', 'price': '64.16', 'amount': '8800', 'display': 'black' }, { 'stock_name': "\u91d1\u53d1\u79d1\u6280", 'stock_symbol': '600143', 'transaction_time': '2010-08-27 09:30:59', 'flag': 'sell', 'price': '10.99', 'amount': '52100', 'display': 'black' }, { 'stock_name': "\u91d1\u53d1\u79d1\u6280", 'stock_symbol': '600143', 'transaction_time': '2010-08-26 13:59:58', 'flag': 'buy', 'price': '10.92', 'amount': '52100', 'display': 'black' }, { 'stock_name': "\u534e\u4ec1\u836f\u4e1a", 'stock_symbol': '300110', 'transaction_time': '2010-08-26 10:35:36', 'flag': 'sell', 'price': '22.57', 'amount': '25300', 'display': 'black' }, { 'stock_name': "\u534e\u4ec1\u836f\u4e1a", 'stock_symbol': '300110', 'transaction_time': '2010-08-25 09:31:05', 'flag': 'buy', 'price': '23.88', 'amount': '25300', 'display': 'black' }, { 'stock_name': "\u90d1\u7164\u673a", 'stock_symbol': '601717', 'transaction_time': '2010-08-24 10:41:38', 'flag': 'sell', 'price': '32.63', 'amount': '18400', 'display': 'black' } ], 'count' : 541, pagesize: 15, 'status' : '1000' }
JSON;
$str=str_replace('\'','"',$str);
$str=preg_replace('/"\s*:([^"]+),\s*"/',"\":\"$1\",\"",$str);
print_r(json_decode($str,true));
<div class="clear">
Hot AI Tools
Undresser.AI Undress
AI-powered app for creating realistic nude photos
AI Clothes Remover
Online AI tool for removing clothes from photos.
Undress AI Tool
Undress images for free
Clothoff.io
AI clothes remover
AI Hentai Generator
Generate AI Hentai for free.
Hot Article
Hot Tools
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Hot Topics
1379
52
Fujifilm X-M5 price expectations rise as leaked selfie display adds complexity to the formerly affordable camera line
Sep 07, 2024 am 09:34 AM
Fujifilm fans were recently very excited at the prospect of the X-T50, since it presented a relaunch of the budget-oriented Fujifilm X-T30 II that had become quite popular in the sub-$1,000 APS-C category. Unfortunately, as the Fujifilm X-T50's launc
Apple Studio Display's power cord is detachable, but requires special tools
May 17, 2023 pm 03:05 PM
Apple Studio Display is now officially available in stores, and many customers around the world have purchased the product. Unlike the ProDisplayXDR, the StudioDisplay has a unique power connector that appears to be non-removable. It turns out that the cable is removable, but you'll need a special tool to remove it. Apple says on its website that the Studio Display's power cord is not detachable -- and many users think so. That's because removing the cable with your hands seems impossible, but luckily the cable can be detached from the monitor. , Apple has a special tool for extracting information from its new StudioDispl
Comparison: Apple Studio Display vs Samsung Smart Monitor M8
May 11, 2023 pm 10:46 PM
Samsung Smart Display M8 vs. Apple Studio Display: Design and Size Since its launch, the Apple Studio Display has been compared to the iMac, consisting of a relatively thin panel on a relatively simple L-shaped stand. It's a well-known and well-loved aesthetic, and Samsung seems to have borrowed it for its presentation. The Samsung SmartMonitor M8 uses the same idea of a thin screen on a stand that looks very similar. Some minor elements are different, such as the small section in the lower left corner that sticks out a bit and the Samsung's chin is very thin, but they seem to be close in terms of basic design. Samsung seems to have taken a lot of inspiration from the 24-inch iMac. Apple's display is smaller than Samsung's
Samsung: New, large display based on E Ink technology displays colors and communicates wirelessly
Jun 19, 2024 pm 03:37 PM
We frequently report on devices based on displays with electronic ink, such as e-readers. The technology offers a number of advantages: it can be read in bright environments without a backlight, and it only requires power when switching without light
Boot Camp updated to support Apple Studio Display
May 20, 2023 pm 11:34 PM
IntelMac users running Windows on a Mac can now update their drivers in BootCamp to support Apple's StudioDisplay. Apple regularly updates BootCamp to introduce support for new hardware, as well as typical compatibility and performance improvements. In the March software update, Apple has enabled BootCamp to work with the new StudioDisplay. The update that brings BootCamp to version 6.1.17 introduces two key support elements. First, it adds compatibility with StudioDisplay, ensuring
Comparison: Apple Studio Display vs LG UltraFine 5K Display: Which one is better?
Apr 16, 2023 pm 08:25 PM
StudioDisplay and LG UltraFine5KDisplay occupy similar positions in the market, but Apple's monitor is $300 more expensive. Here's everything you need to know about how these monitors compare. Six years is a long time in the tech world, and it's also the time since Apple has sold a branded monitor that costs less than $5,000. During this time, Apple partnered with LG to sell the LG UltraFine series, which catered specifically to Mac users. In 2019, Apple stopped selling these LG monitors in favor of ProDisplayXDR, an affordable Mac-friendly display
What values does display have?
Nov 20, 2023 pm 05:28 PM
The values of display include block, inline, none, inline-block, flex, grid, table, inline-table and list-item. Detailed introduction: 1. block, which renders elements into block-level elements. Block-level elements form a block on the page and occupy one line alone; 2. inline, which renders elements into inline elements. Inline elements will not occupy a line by themselves and can be side by side with other elements; 3. none, this value specifies that the element will not be on the page, etc.
Apple Studio Display works on Windows with some limitations
Apr 14, 2023 pm 03:49 PM
Apple this week announced Studio Display, which features a 27-inch 5K panel that combines a camera, microphone, and speakers that work together when users connect the display to their Mac. Where are the windows? If for some reason you need to use Apple's $1,599 monitor with a Windows PC, you can, but there are some limitations. When plugged into a Windows PC via a Thunderbolt connection (not supported by every PC), the StudioDisplay is recognized as a regular monitor. That said, if you buy one of these to use it with Windows, you'll want to remember


