PHP to JSON format -


मैं JSON प्रारूप प्राप्त कर रहा हूं:

  {"test": [{" Key1 ":" value1 "}, {" key2 ":" value2 "}]}   

लेकिन इसके बजाय इस प्रारूप को प्राप्त करना संभव है?

  {"Test1": {"key1": "value1", "key2": "value2"}}   

मेरा php कोड यह है:

  $ कुंजी = $ पंक्ति [1]; $ मूल्य = $ पंक्ति [2]; $ Posts [] = सरणी ($ कुंजी = & gt; $ मान); $ प्रतिक्रिया ['तार'] = $ पद; फ़िलिट ($ आउट, json_Encode ($ प्रतिक्रिया))   

मैं घंटों के लिए इस पर फंस गया हूं, कृपया कोई मदद करें! अग्रिम धन्यवाद!

आप चाहते हैं

  $ posts [$ key ] = $ मान;   

समस्या यह है कि स्ट्रिंग कुंजी के साथ PHP सरणियों को JSON शब्दों में ऑब्जेक्ट हैं।

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -