doy51723 2015-01-19 10:49
浏览 56
已采纳

当使用php从webserver读取时,JSON文件返回null。

I have a .json file uploaded on my web server with valid syntax.( http://www.isoivit.in/Details.json).

I want to edit it using php. My php code is as given below:

<?php
   $jsonString = file_get_contents('http:/www.isoivit.in/json/Details.json');
preg_replace("/\s+/", " ", $jsonString);
/*$jsonString='{
    
    "events_info":{
        "total_events": "3", 
    
        "events":[
            {
                    "id": "1",
                    "name": "JUST F.A.S.T",
                    "image":"events_image1",
            "short_des":"JUST F.A.S.T(Finding an Answer is So Tricky) It is 

an interesting and enthusiastic game. You must be so fast in finding the tricky 

answers.",
            "med_des":" It is an interesting and enthusiastic game.
You 

must be so fast in finding the tricky answers. It has four rounds. In the first 2 rounds 

the questionnaire would be funny and enjoyable which includes few audio and video clips 

also.
There will be a rapid fire round based on themes of Riviera and also 

interesting tasks to be done in the final round. Exciting rewards will be given after 

the clearance of 2nd and 3rd rounds.So gear up people, to experience the boundless fun.


",
            "full_des":"1) It has 4 rounds.
2) In first round 5 questions 

will be asked and there will be a time limit. The questions will not be general 

knowledge or current affairs based. They will be funny riddles and tricky questions.


3)In second round questions will be mostly based on audios and visuals. Eg: an audio 

of any cartoon character will be played and they have to recognize that cartoon 

character.
4)They can use lifelines in first 2 rounds like skip a question, take 

audience help.
5) The third round will be a rapid fire round. In this round we will 

provide them few topics and they need to choose one of them(those topics will be related 

to the theme of Riviera, like Indian cricket ,etc.).The participant will be asked 

questions on the topic of his choice.
6)The fourth round will be held on the fourth 

day. The participant will be given 3 tasks to perform. They are:
---> They will be 

given riddles in different languages other than English and Hindi. They need to know 

which language it is and solve the riddle. 
--->They need to bring outdated posters 

from the whole VIT. Specific time limit will be given. 
---> They need to get 

autographs or photos of tags of organizers and managers of Riviera.
7)Apart from this 

audience also will have their set of interesting questions. Their answers will be taken 

into consideration and rewards are given to the lucky persons.
",
                    "details":" Prize Money :

1st- Rs.2000\/- 
2nd- 

Rs.1500\/- 
3rd- Rs.1000\/-
Registration fee:

Rs.100 per member
Event 

Coordinators

N.Sai Mounika 
mouni123.nekkalapudi@gmail.com 
 "
            },
        {
                    "id": "2",
                    "name": "Speeling Bee",
                    "image":"events_image2",
            "short_des":"Spelling Bee is a competition in which contestants 

are asked to spell a broad selection of words, usually with a varying degree of 

difficulty.",
            "med_des":" Spelling Bee is a competition in which contestants 

are asked to spell a broad selection of words, usually with a varying degree of 

difficulty.
It has three rounds.
First round- 
In first round, audio of 25 

words is played and participants need to write them on paper.Based on the score top ten 

people are screened. 

Second round- 
In second round, 5 questions are asked to 

each 10 participants. 

Third round- 
Third or final round is a buzzer round.10 

questions are asked. 
There are negative marks for wrong answers in this round. 


Based on scores of 2nd and third round,winner and runner-up are decided.
",
            "full_des":"",
                    "details":" 
Prize Money :

1st- Rs.2000\/- 
2nd- 

Rs.1500\/- 
3rd- Rs.1000\/-
Registration fee:

Rs.100 per member
Event 

Coordinators

Pranay Yenigandla 
pranay.pranu111@gmail.com
Shreyash Saurabh


 "
            },

        {
                    "id": "3",
                    "name": "Be Crazy",
                    "image":"events_image3",
            "short_des":" Do you wanna do something crazy? !!! Here is our 

event \"Be Crazy\"-Crazyness in peaks.",
            "med_des":" Do you wanna do something crazy? !!! Here is our 

event \"Be Crazy\"-Crazyness in peaks.
Do you think that you are a bit crazy among 

your friends..!!!Here is our event for this RIVEIRA2015.
In this event you are given 

some crazy tasks to perform with time limit in levels of 1,2 &3.like \"Shot A Celebrete 

-in this event u have to get a selfie with organisers and famous personalities of VIT

\"
",
            "full_des":" We have 3 rounds in this event.
1st round has 10 

simpler tasks.
Examples:
>>Forming towers with paper cups
>>Lemon spoon race


>>Walk in grills without touching
>>Run the race with legs tied together
>>Lift 

the rod holding from edge
>>Skipping race
2nd round has 5 tasks.
Examples:


>>Sac race
>>Hold the wet brick with two fingers
>>Get a photo with organizers 

of RIVEIRA (10)
3rd round has 2-3 tasks like
Examples:
>>catch the paper 

between fingers when it is released
Each task is given its own credits. The time 

taken to complete every task is noted for every team. Teams which are leading in that 

task in terms of time will get credits. At the end of first round depending on the 

credits they will be qualified to the second round. In the similar manner people will be 

selected to the third round also. winners are announced after the third round depending 

on their credits.
We will select top 20 teams from round 1 that will qualify to round 

2.
We will select top10 teams from round 2 that will qualify round 3.
We will 

decide qualifiers for each round on basis of points and time taken to complete a task.


",
                    "details":" Prize Money :

1st- Rs.3000\/-
2nd- 

Rs.2000\/-
3rd- Rs.1000\/-
Registration fee:

Rs 150\/- per team
No of 

participants per team:

5(Maximum)
Event Coordinators
 
K. Jaswanth 

Kumar
jaswanthjaan@gmail.com
Ankush Saini
ankushsaini88@gmail.com
"
            }
        ]
    },
    "archives_info":{
        "total_events": "2", 
    
        "events":[
            {
                    "id": "1",
                    "name": "Explore Matlab",
                    "image":"archives_image1",
            "short_des":" It is a five day free workshop.
MATLAB (matrix 

laboratory) is a multi-paradigm numerical computing environment and fourth-generation 

programming language. Developed by MathWorks, MATLAB allows matrix manipulations, 

plotting of functions and data, implementation of algorithms, creation of user 

interfaces, and interfacing with programs written in other languages, including C, C++, 

Java, Fortran and Python.
The workshop aims to develop the vision and skills 

MATLAB.The workshop is one of the huge success with approximately 400 students attending 

the workshop every year .
",
            "med_des":"",
            "full_des":"",
                    "details":"1) Basics of MATLAB.
2) MATLAB Simulink.
3) 

Fundamentals of Signals & Systems using MATLAB.
4) Probability & Random Processes 

using MATLAB.
5) Analysis & Design of Control System using MATLAB.
6) Modelling & 

Simulation of Signal Processing Application.
7) Artificial Neural Network using 

MATLAB.
"
            },
        {
                    "id": "2",
                    "name": "See The C",
                    "image":"archives_image2",
            "short_des":" It is a free workshop for all the students to 

develop their programming skills used in the field of Computer Science. C is the most 

widely used programming languages of all time and C compilers are available for the 

majority of available computer architecture and operating systems.
This workshop is 

to help first years to learn a new language in which most of them find difficulty to 

learn.
",
            "med_des":"",
            "full_des":"",
                    "details":"1) C Language is a general-purpose programming 

language .C has facilities for structured programming and allows lexical variable scope 

and recursion.
2) Its design provides constructs that map efficiently to typical 

machine instructions and therefore it has found lasting use in applications that had 

formerly been coded in assembly language.
3) The C programming language uses 

libraries as its primary method of extension. In C, a library is a set of functions 

contained within a single \"archive\" file. Each library typically has a header file, 

which contains the prototypes of the functions contained within the library that may be 

used by a program, and declarations of special data types and macro symbols used with 

these functions.
4) C has been used successfully for every type of programming 

problem imaginable from operating systems to spreadsheets to expert systems - and 

efficient compilers are available for machines ranging in power from the Apple Macintosh 

to the Cray supercomputers.
5) Tools have been created to help C programmers avoid 

some of the problems inherent in the language, such as statements with undefined 

behavior or statements that are not a good practice because they are likely to result in 

unintended behavior or run-time errors.
6) Despite its low-level capabilities, the 

language was designed to encourage cross-platform programming. A standards-compliant and 

portably written C program can be compiled for a very wide variety of computer platforms 

and operating systems with few changes to its source code
7) With regards to personal 

computers Microsoft C for IBM (or clones) PC\'s. and Borlands C are seen to be the two 

most commonly used systems. However, the latest version of Microsoft C is now considered 

to be the most powerful and efficient C compiler for personal computers.
"
            }
        ]
    },
    "riviera_info":{
        "total_events": "3", 
    
        "events":[
            {
                    "id": "1",
                    "name": "JUST F.A.S.T",
                    "image":"riviera_image1",
            "short_des":"JUST F.A.S.T(Finding an Answer is So Tricky) It is 

an interesting and enthusiastic game. You must be so fast in finding the tricky 

answers.",
            "med_des":" It is an interesting and enthusiastic game.
You 

must be so fast in finding the tricky answers. It has four rounds. In the first 2 rounds 

the questionnaire would be funny and enjoyable which includes few audio and video clips 

also.
There will be a rapid fire round based on themes of Riviera and also 

interesting tasks to be done in the final round. Exciting rewards will be given after 

the clearance of 2nd and 3rd rounds.So gear up people, to experience the boundless fun.


",
            "full_des":"1) It has 4 rounds.
2) In first round 5 questions 

will be asked and there will be a time limit. The questions will not be general 

knowledge or current affairs based. They will be funny riddles and tricky questions.


3)In second round questions will be mostly based on audios and visuals. Eg: an audio 

of any cartoon character will be played and they have to recognize that cartoon 

character.
4)They can use lifelines in first 2 rounds like skip a question, take 

audience help.
5) The third round will be a rapid fire round. In this round we will 

provide them few topics and they need to choose one of them(those topics will be related 

to the theme of Riviera, like Indian cricket ,etc.).The participant will be asked 

questions on the topic of his choice.
6)The fourth round will be held on the fourth 

day. The participant will be given 3 tasks to perform. They are:
---> They will be 

given riddles in different languages other than English and Hindi. They need to know 

which language it is and solve the riddle. 
--->They need to bring outdated posters 

from the whole VIT. Specific time limit will be given. 
---> They need to get 

autographs or photos of tags of organizers and managers of Riviera.
7)Apart from this 

audience also will have their set of interesting questions. Their answers will be taken 

into consideration and rewards are given to the lucky persons.
",
                    "details":" Prize Money :

1st- Rs.2000\/- 
2nd- 

Rs.1500\/- 
3rd- Rs.1000\/-
Registration fee:

Rs.100 per member
Event 

Coordinators

N.Sai Mounika 
mouni123.nekkalapudi@gmail.com 
 "
            },
        {
                    "id": "2",
                    "name": "Speeling Bee",
                    "image":"riviera_image2",
            "short_des":"Spelling Bee is a competition in which contestants 

are asked to spell a broad selection of words, usually with a varying degree of 

difficulty.",
            "med_des":" Spelling Bee is a competition in which contestants 

are asked to spell a broad selection of words, usually with a varying degree of 

difficulty.
It has three rounds.
First round- 
In first round, audio of 25 

words is played and participants need to write them on paper.Based on the score top ten 

people are screened. 

Second round- 
In second round, 5 questions are asked to 

each 10 participants. 

Third round- 
Third or final round is a buzzer round.10 

questions are asked. 
There are negative marks for wrong answers in this round. 


Based on scores of 2nd and third round,winner and runner-up are decided.
",
            "full_des":"",
                    "details":" 
Prize Money :

1st- Rs.2000\/- 
2nd- 

Rs.1500\/- 
3rd- Rs.1000\/-
Registration fee:

Rs.100 per member
Event 

Coordinators

Pranay Yenigandla 
pranay.pranu111@gmail.com
Shreyash Saurabh


 "
            },

        {
                    "id": "3",
                    "name": "Be Crazy",
                    "image":"riviera_image3",
            "short_des":" Do you wanna do something crazy? !!! Here is our 

event \"Be Crazy\"-Crazyness in peaks.",
            "med_des":" Do you wanna do something crazy? !!! Here is our 

event \"Be Crazy\"-Crazyness in peaks.
Do you think that you are a bit crazy among 

your friends..!!!Here is our event for this RIVEIRA2015.
In this event you are given 

some crazy tasks to perform with time limit in levels of 1,2 &3.like \"Shot A Celebrete 

-in this event u have to get a selfie with organisers and famous personalities of VIT

\"
",
            "full_des":" We have 3 rounds in this event.
1st round has 10 

simpler tasks.
Examples:
>>Forming towers with paper cups
>>Lemon spoon race


>>Walk in grills without touching
>>Run the race with legs tied together
>>Lift 

the rod holding from edge
>>Skipping race
2nd round has 5 tasks.
Examples:


>>Sac race
>>Hold the wet brick with two fingers
>>Get a photo with organizers 

of RIVEIRA (10)
3rd round has 2-3 tasks like
Examples:
>>catch the paper 

between fingers when it is released
Each task is given its own credits. The time 

taken to complete every task is noted for every team. Teams which are leading in that 

task in terms of time will get credits. At the end of first round depending on the 

credits they will be qualified to the second round. In the similar manner people will be 

selected to the third round also. winners are announced after the third round depending 

on their credits.
We will select top 20 teams from round 1 that will qualify to round 

2.
We will select top10 teams from round 2 that will qualify round 3.
We will 

decide qualifiers for each round on basis of points and time taken to complete a task.


",
                    "details":" Prize Money :

1st- Rs.3000\/-
2nd- 

Rs.2000\/-
3rd- Rs.1000\/-
Registration fee:

Rs 150\/- per team
No of 

participants per team:

5(Maximum)
Event Coordinators
 
K. Jaswanth 

Kumar
jaswanthjaan@gmail.com
Ankush Saini
ankushsaini88@gmail.com
"
            }
        ]
    }
    
}


';*/
echo $jsonString;
echo '...............................................';
$data=json_decode($jsonString,true);

var_dump($data);
//$data1=json_decode($data['events_info'],true);
//var_dump($data1);
$var1= $data['events_info'];
$var2= $var1['events'];
$var3=$var2[0];
echo $var3['name'];
echo json_last_error();?>

In the comment section of my php script is the whole json string copied from web. The problem I am facing is that when I use json_decode on the string returned by file_get_contents('http:/www.isoivit.in/json/Details.json') it returns NULL, while when I use json_decode on the string which is copied from same json file I get a valid output what I desire. This means that my php code is able to read json file from web but unable to decode it. I get a json last error 4(SYNTAX ERROR). Though I have checked for all errors and its running feasibly on my android application. Please help.

</div>
  • 写回答

1条回答 默认 最新

  • dongshanjin8947 2015-01-19 11:07
    关注

    You have only one / in the http://, you should change to http://www.isoivit.in/json/Details.json and you get NULL because of the \' from PC\'s (it decodes with simple unescaped ' then it get's into conflict with json_decode. You could do:

    $jsonString =  file_get_contents('http://www.isoivit.in/json/Details.json');
    $jsonString = str_replace("\\'", "\\\\'", $jsonString); // double encode the single quote
    $jsonString = json_decode($jsonString, true);
    
    print_r($jsonString);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大