【问题标题】:php "json?" decode issuephp“json?”解码问题
【发布时间】:2023-03-05 09:36:01
【问题描述】:

我从 mysql 得到这个,需要帮助解码...

[{\"label\":\"Text Field\",\"value\":\"\",\"identifier\":\"field20\",\"type\":\"customText\",\"page\":1,\"page_name\":\"Step 1\",\"width\":\"100%\"},{\"label\":\"Name\",\"value\":\"thisisafirstname\",\"identifier\":\"field3\",\"type\":\"oneLineText\",\"page\":1,\"page_name\":\"Step 1\",\"width\":\"50%\"},{\"label\":\"Name\",\"value\":\"thisisalastname\",\"identifier\":\"field39\",\"type\":\"oneLineText\",\"page\":1,\"page_name\":\"Step 1\",\"width\":\"50%\"},{\"label\":\"Phone Number\",\"value\":\"555-555-5555\",\"identifier\":\"field2\",\"type\":\"oneLineText\",\"page\":1,\"page_name\":\"Step 1\",\"width\":\"100%\"},{\"label\":\"Email\",\"value\":\"thisisanemail@examplemail.com\",\"identifier\":\"field4\",\"type\":\"email\",\"page\":1,\"page_name\":\"Step 1\",\"width\":\"100%\"},{\"label\":\"How would you like to help?\",\"value\":[\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"11\"],\"identifier\":\"field6\",\"type\":\"checkbox\",\"page\":1,\"page_name\":\"Step 1\",\"options\":[{\"value\":\"1\",\"show\":\"Project\"},{\"value\":\"2\",\"show\":\"Internship\"},{\"value\":\"3\",\"show\":\"Externship\"},{\"value\":\"4\",\"show\":\"Adviser\"},{\"value\":\"5\",\"show\":\"Judge\"},{\"value\":\"6\",\"show\":\"Council\"},{\"value\":\"7\",\"show\":\"Contribution\"},{\"value\":\"8\",\"show\":\"Speaker\"},{\"value\":\"9\",\"show\":\"Field Trip\"},{\"value\":\"10\",\"show\":\" Job Shadowing\"},{\"value\":\"11\",\"show\":\" Other\"}],\"width\":\"100%\"},{\"label\":\"Start of\",\"value\":\"15\\/07\\/2015\",\"identifier\":\"field33\",\"type\":\"datepicker\",\"page\":1,\"page_name\":\"Step 1\",\"width\":\"50%\"},{\"label\":\"End of\",\"value\":\"16\\/07\\/2015\",\"identifier\":\"field34\",\"type\":\"datepicker\",\"page\":1,\"page_name\":\"Step 1\",\"width\":\"50%\"},{\"label\":\"Who would you like to help?\",\"value\":\"3\",\"identifier\":\"field7\",\"type\":\"checkbox\",\"page\":1,\"page_name\":\"Step 1\",\"options\":[{\"value\":\"1\",\"show\":\"Entire County\"},{\"value\":\"2\",\"show\":\"Specific County Academies\"},{\"value\":\"3\",\"show\":\"Specific Schools\"}],\"width\":\"100%\"},{\"label\":\"County Academy Styles\",\"value\":\"\",\"identifier\":\"field21\",\"type\":\"checkbox\",\"page\":1,\"page_name\":\"Step 1\",\"options\":[{\"value\":\"1\",\"show\":\"Business\"},{\"value\":\"2\",\"show\":\"Arts and Communication\"},{\"value\":\"3\",\"show\":\"Healthcare\"},{\"value\":\"4\",\"show\":\"STEM\"},{\"value\":\"5\",\"show\":\"Leadership, Law and Public Service\"}],\"width\":\"100%\"},{\"label\":\"Schools\",\"value\":\"4\",\"identifier\":\"field8\",\"type\":\"checkbox\",\"page\":1,\"page_name\":\"Step 1\",\"options\":[{\"value\":\"1\",\"show\":\"Berkmar\"},{\"value\":\"2\",\"show\":\"Central\"},{\"value\":\"3\",\"show\":\"Discovery\"},{\"value\":\"4\",\"show\":\"Lanier\"},{\"value\":\"5\",\"show\":\"Meadowcreek\"},{\"value\":\"6\",\"show\":\"Shiloh\"},{\"value\":\"7\",\"show\":\"South\"}],\"width\":\"100%\"},{\"label\":\"Berkmar\'s Academies\",\"value\":\"\",\"identifier\":\"field36\",\"type\":\"checkbox\",\"page\":1,\"page_name\":\"Step 1\",\"options\":[{\"value\":\"1\",\"show\":\"Science, Technology, Engineering & Mathematics (STEM)\"},{\"value\":\"2\",\"show\":\"Health and Human Services\"},{\"value\":\"3\",\"show\":\"Media, Arts & Communication\"},{\"value\":\"4\",\"show\":\"Free Enterprise and Leadership\"},{\"value\":\"5\",\"show\":\"Architecture & Construction\"}],\"width\":\"100%\"},{\"label\":\"Centeral\'s Academies\",\"value\":\"\",\"identifier\":\"field9\",\"type\":\"checkbox\",\"page\":1,\"page_name\":\"Step 1\",\"options\":[{\"value\":\"1\",\"show\":\"Business&Entrepreneurship\"},{\"value\":\"2\",\"show\":\"Fine Arts&Communication\"},{\"value\":\"3\",\"show\":\"Law, Education&Public Service\"},{\"value\":\"4\",\"show\":\"Medical&Health Care Sciences\"},{\"value\":\"5\",\"show\":\"STEM\"}],\"width\":\"100%\"},{\"label\":\"Discovery\'s Academies\",\"value\":\"\",\"identifier\":\"field37\",\"type\":\"checkbox\",\"page\":1,\"page_name\":\"Step 1\",\"options\":[{\"value\":\"1\",\"show\":\"Science, Technology, Engineering & Mathematics (STEM)\"},{\"value\":\"2\",\"show\":\"Health & Human Services\"},{\"value\":\"3\",\"show\":\"Media, Arts & Communication\"},{\"value\":\"4\",\"show\":\"Business Administration & Entrepreneurship\"}],\"width\":\"100%\"},{\"label\":\"Lanier\'s Academies\",\"value\":\"5\",\"identifier\":\"field10\",\"type\":\"checkbox\",\"page\":1,\"page_name\":\"Step 1\",\"options\":[{\"value\":\"1\",\"show\":\"Multimedia&Fine Arts\"},{\"value\":\"2\",\"show\":\"Public Service&Leadership\"},{\"value\":\"3\",\"show\":\"Life&Health Sciences\"},{\"value\":\"4\",\"show\":\"Global Business&Entrepreneurship\"},{\"value\":\"5\",\"show\":\"CDAT\"}],\"width\":\"100%\"},{\"label\":\"Meadowcreek\'s Academies\",\"value\":\"\",\"identifier\":\"field11\",\"type\":\"checkbox\",\"page\":1,\"page_name\":\"Step 1\",\"options\":[{\"value\":\"1\",\"show\":\"Communication&Arts\"},{\"value\":\"2\",\"show\":\"Information Technology\"},{\"value\":\"3\",\"show\":\"Health&Hospitality\"},{\"value\":\"4\",\"show\":\"International Business\"},{\"value\":\"5\",\"show\":\"STEM\"}],\"width\":\"100%\"},{\"label\":\"Shiloh\'s Academies\",\"value\":\"\",\"identifier\":\"field12\",\"type\":\"checkbox\",\"page\":1,\"page_name\":\"Step 1\",\"options\":[{\"value\":\"1\",\"show\":\"Arts, Media&Entertainment\"},{\"value\":\"2\",\"show\":\"Wellness, Health&Education\"},{\"value\":\"3\",\"show\":\"Marketing&Leadership\"},{\"value\":\"4\",\"show\":\"Science&Technology\"}],\"width\":\"100%\"},{\"label\":\"South\'s Academies\",\"value\":\"\",\"identifier\":\"field13\",\"type\":\"checkbox\",\"page\":1,\"page_name\":\"Step 1\",\"options\":[{\"value\":\"1\",\"show\":\"Business&Entrepreneurship\"},{\"value\":\"2\",\"show\":\"Health&Human Services\"},{\"value\":\"3\",\"show\":\"Media Arts&Communications\"},{\"value\":\"4\",\"show\":\"Public Service, Law&Leadership\"},{\"value\":\"5\",\"show\":\"STEM\"}],\"width\":\"100%\"},{\"label\":\"Name\",\"value\":\"thisisacompanyname\",\"identifier\":\"field16\",\"type\":\"oneLineText\",\"page\":1,\"page_name\":\"Step 1\",\"width\":\"100%\"},{\"label\":\"Brief description\",\"value\":\"thisisabriefdescription\",\"identifier\":\"field17\",\"type\":\"textarea\",\"page\":1,\"page_name\":\"Step 1\",\"width\":\"100%\"},{\"label\":\"Who Referred You?\",\"value\":\"12\",\"identifier\":\"field40\",\"type\":\"checkbox\",\"page\":1,\"page_name\":\"Step 1\",\"options\":[{\"value\":\"1\",\"show\":\"John Tronolone (Berkmar)\"},{\"value\":\"2\",\"show\":\"Joshua Allen (Central)\"},{\"value\":\"3\",\"show\":\"Marlene Taylor-Crawford (Discovery)\"},{\"value\":\"4\",\"show\":\"Scott Allen (Discovery)\"},{\"value\":\"5\",\"show\":\"Kyle Jones (Lanier)\"},{\"value\":\"6\",\"show\":\"Diane Luong (Shiloh)\"},{\"value\":\"7\",\"show\":\"Elizabeth Schneider (Shiloh)\"},{\"value\":\"8\",\"show\":\"Tara Haynes (South)\"},{\"value\":\"9\",\"show\":\"Other (Berkmar)\"},{\"value\":\"10\",\"show\":\"Other (Central)\"},{\"value\":\"11\",\"show\":\"Other (Discovery)\"},{\"value\":\"12\",\"show\":\"Other (Lanier)\"},{\"value\":\"13\",\"show\":\"Other (Meadowcreek)\"},{\"value\":\"14\",\"show\":\"Other (Shiloh)\"},{\"value\":\"15\",\"show\":\"Other (South)\"},{\"value\":\"16\",\"show\":\"Other\"}],\"width\":\"100%\"},{\"label\":\"Captcha\",\"value\":\"\",\"identifier\":\"field28\",\"type\":\"reCaptcha\",\"page\":1,\"page_name\":\"Step 1\",\"width\":\"100%\"}]

这就是我对 php 所做的

$array = json_decode($json, true);
print_r($array);

【问题讨论】:

  • 你应该使用print_r($array)。您还有什么其他问题?
  • @JayBlanchard 它没有打印任何东西
  • 字符串在所有引号之前真的有反斜杠吗?这不是有效的 JSON。
  • 那是无效的 json.... 你可以试试stripslashes(),但如果它删除了应该存在的反斜杠,这可能会导致其他类型的损坏。你需要修复产生这个坏 json 的任何东西。
  • @Barmar 这就是为什么我放了一个问号“json?”因为我不确定......我需要帮助来解码这个

标签: php mysql json


【解决方案1】:

正如大家所说,这可能会破坏其他东西,但试试这个:

$array = json_decode(stripslashes($json), true);
print_r($array);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多