0o0o0 Posted April 19, 2012 Share Posted April 19, 2012 Anyone? Ive parced before but this maybe too complex?? {"page_number":1,"total_rows":3,"date":"April, 19 2012 00:44:42","stats":[ {"rnk":1,"top":4,"ref":1000007,"3Per":1.0,"sts":4,"w":2,"p":2,"sF":00112,"es":8.0020,"reg":"X","hN":"Defence","s":0,"winP":0.98}, {"rnk":3,"top":2,"ref":1000001,"3Per":1.0,"sts":4,"w":2,"p":2,"sF":00112,"es":8.0020,"reg":"X","hN":"Defence","s":0,"winP":0.98}, {"rnk":2,"top":4,"ref":1000000,"3Per":1.0,"sts":4,"w":2,"p":2,"sF":00111,"es":7.0002,"reg":"X","hN":"Forward","s":9,"winP":0.12}]} fields.. rnk, top, ref, 3Per, sts, w, p, sF, es, reg, hN, s winP... all after the : is the data I want. Ive done csv before its simple with , ' but this.. need a little help if possible. exclude {"page_number":1,"total_rows":2,"date":"April, 19 2012 00:44:42","stats": and start from [ to ] its orignally a text file.. to mysql is the plan. Quote Link to comment https://forums.phpfreaks.com/topic/261228-anyone-with-some-insight-on-parcing-this-text-to-mysql-database/ Share on other sites More sharing options...
requinix Posted April 19, 2012 Share Posted April 19, 2012 That's JSON. decode it then loop through the stats array doing whatever you want. Quote Link to comment https://forums.phpfreaks.com/topic/261228-anyone-with-some-insight-on-parcing-this-text-to-mysql-database/#findComment-1338660 Share on other sites More sharing options...
0o0o0 Posted April 19, 2012 Author Share Posted April 19, 2012 hmm Quote Link to comment https://forums.phpfreaks.com/topic/261228-anyone-with-some-insight-on-parcing-this-text-to-mysql-database/#findComment-1338663 Share on other sites More sharing options...
0o0o0 Posted April 19, 2012 Author Share Posted April 19, 2012 anyone done json before?? any simple tutorials?? everything ive searched on the net for the past 3 hours is like live from one site to another site.. I just need a simple parse and rewrite file to either appear like a csv file (because thats what im familiar with) or auto input into a mysql database if its possible and less load on the server. thanks. Just a links great! .. or a quick sample code if you have the time. Thx. Quote Link to comment https://forums.phpfreaks.com/topic/261228-anyone-with-some-insight-on-parcing-this-text-to-mysql-database/#findComment-1338701 Share on other sites More sharing options...
trq Posted April 19, 2012 Share Posted April 19, 2012 Use parse_json to parse the json into a format that can be easily handled with php. Quote Link to comment https://forums.phpfreaks.com/topic/261228-anyone-with-some-insight-on-parcing-this-text-to-mysql-database/#findComment-1338703 Share on other sites More sharing options...
0o0o0 Posted April 19, 2012 Author Share Posted April 19, 2012 Ok another 3 hours later.. json_encode json_decode and json_parse ... not gettin it. how does it know where the 's are the "'s are the :'s are??? im really old school is everything pluggins today?? like wordpress etc.. I viewed the examples online and thought... how is it possible? ... is todays coding less work? .... when I was younger we had to build/code it all from scratch.. and BOTHS WAYS!!. (new age old guy) {"page_number":1,"total_rows":3,"date":"April, 19 2012 00:44:42","stats": [{"rnk":1,"top":4,"ref":1000007,"3Per":1.0,"sts":4,"w":2,"p":2,"sF":00112,"es":8.0020,"reg":"X","hN":"Defence","s":0,"winP":0.98}, {"rnk":3,"top":2,"ref":1000001,"3Per":1.0,"sts":4,"w":2,"p":2,"sF":00112,"es":8.0020,"reg":"X","hN":"Defence","s":0,"winP":0.98}, {"rnk":2,"top":4,"ref":1000000,"3Per":1.0,"sts":4,"w":2,"p":2,"sF":00111,"es":7.0002,"reg":"X","hN":"Forward","s":9,"winP":0.12}]} tell me how youd rip the "rnk" numbers and the "top" numbers.. It'll at least give me a jumpstart.. do you guys still do that today?? jumpstart cars? oh great lost another commadore key.. thats ok I still got the VIC for backup. Quote Link to comment https://forums.phpfreaks.com/topic/261228-anyone-with-some-insight-on-parcing-this-text-to-mysql-database/#findComment-1338745 Share on other sites More sharing options...
trq Posted April 19, 2012 Share Posted April 19, 2012 when I was younger we had to build/code it all from scratch And yet you still can't deal with a simple array structure? im really old school is everything pluggins today?? Us youngsters simply choose to use the right tools for the job. No point reinventing the wheel. Now, what have you tried? Post some code and a description of your actual problem. Quote Link to comment https://forums.phpfreaks.com/topic/261228-anyone-with-some-insight-on-parcing-this-text-to-mysql-database/#findComment-1338751 Share on other sites More sharing options...
0o0o0 Posted April 19, 2012 Author Share Posted April 19, 2012 Thats fine, to anyone else out there who came to this thread for insite, heres the best possible read online.. trust me ive been to 121 pages in 6 hours. http://roshanbh.com.np/2008/10/creating-parsing-json-data-php.html goodluck! Quote Link to comment https://forums.phpfreaks.com/topic/261228-anyone-with-some-insight-on-parcing-this-text-to-mysql-database/#findComment-1338756 Share on other sites More sharing options...
batwimp Posted April 19, 2012 Share Posted April 19, 2012 My machine gave a syntax error on the json you provided. For some reason, it didn't like this part: "sF":00112 because it starts with zeros. It doesn't like a single zero either, though this link: http://www.json.org/ shows that it should be able to start with one zero (which it still errors out if it does). You may want to fix these errors before you keep messing around with json. Quote Link to comment https://forums.phpfreaks.com/topic/261228-anyone-with-some-insight-on-parcing-this-text-to-mysql-database/#findComment-1338771 Share on other sites More sharing options...
0o0o0 Posted April 19, 2012 Author Share Posted April 19, 2012 hey thorpe mighty god of wisdom, ya might wanna scroll up and click on the parse_json() link ya sent me.. thats when I started waiting for someone elses help. but thanks pal. Quote Link to comment https://forums.phpfreaks.com/topic/261228-anyone-with-some-insight-on-parcing-this-text-to-mysql-database/#findComment-1338796 Share on other sites More sharing options...
trq Posted April 19, 2012 Share Posted April 19, 2012 Aww, so sorry. It was json_decode not json_parse. It must have been very difficult to search the manual for the word *json*. Quote Link to comment https://forums.phpfreaks.com/topic/261228-anyone-with-some-insight-on-parcing-this-text-to-mysql-database/#findComment-1338915 Share on other sites More sharing options...
Jessica Posted April 20, 2012 Share Posted April 20, 2012 hey thorpe mighty god of wisdom, ya might wanna scroll up and click on the parse_json() link ya sent me.. thats when I started waiting for someone elses help. but thanks pal. And with thanks like that I can't imagine why no one else wants to help! Quote Link to comment https://forums.phpfreaks.com/topic/261228-anyone-with-some-insight-on-parcing-this-text-to-mysql-database/#findComment-1338933 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.