当前位置: 首页>>代码示例>>PHP>>正文


PHP JSON::parse方法代码示例

本文整理汇总了PHP中JSON::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP JSON::parse方法的具体用法?PHP JSON::parse怎么用?PHP JSON::parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JSON的用法示例。


在下文中一共展示了JSON::parse方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: foreach

    # the file with the newly uploaded content.
    foreach ($data['data'] as $field) {
        # Set Filename
        $filename = ROOT_DIR . '/' . PUBLIC_ROOT . '/content/field-' . $field['ID'] . '.html';
        # Check for file
        if (!file_exists($filename)) {
            $unsaved++;
        }
        # Attempt to save content
        if (file_exists($filename) && file_put_contents($filename, $field['content'])) {
            $saved++;
        }
    }
    # Check for success
    switch (true) {
        # All saved
        case $saved > 0 && $unsaved === 0:
            JSON::parse(200, 'positive', '<i class="fa fa-check-circle"></i> Changes saved.', null, true);
            break;
            # Some saved
        # Some saved
        case $saved > 0 && $unsaved > 0:
            JSON::parse(200, 'warning', '<i class="fa fa-check-circle"></i> Some changes were not saved.', null, true);
            break;
            # No saved
        # No saved
        case $saved === 0 && $unsaved > 0:
            JSON::parse(200, 'negative', '<i class="fa fa-check-circle"></i> Changes were not saved.', array(0 => ROOT_DIR . '/' . PUBLIC_ROOT . '/content/field-' . $field['ID'] . '.html'), true);
            break;
    }
}
开发者ID:chrismademe,项目名称:frontend-editor,代码行数:31,代码来源:ce-update.php

示例2: GUMP

        break;
}
# New GUMP Object
$form = new GUMP();
# Get Input
$data = form_data();
# Validate Input
$form->validate($data, array('files' => 'required'));
# Run GUMP
$response = $form->run($data);
# Get Response
if ($response === false) {
    JSON::parse(100, 'negative', $form->get_readable_errors(true));
} else {
    # Split Base64
    $parts = explode(';', $data['files']);
    # Split Type
    $type = explode('/', $parts[0]);
    # File Extension
    $ext = $type[1];
    # Get File
    $file = base64_decode(preg_replace('#^data:image/\\w+;base64,#i', '', $data['files']));
    # Set filename
    $filename = ROOT_DIR . '/site/_media/' . time() . '.' . $ext;
    # Save File
    if (file_put_contents($filename, $file)) {
        JSON::parse(200, 'positive', 'Image saved', array('url' => str_replace(ROOT_DIR, '', $filename)), true);
    } else {
        JSON::parse(100, 'negative', 'Unable to save file', null, true);
    }
}
开发者ID:chrismademe,项目名称:php-starter,代码行数:31,代码来源:ce-upload.php

示例3: Content

<?php

use CCK\Content;
# Create Content Object
$content = new Content($_cck_types, $_cck_config);
# Create Content
$content->create(form_data());
# Get Response
$response = $content->getResponse();
# Create Response Type
switch (true) {
    # Negative
    case $response['code'] === 100:
        $response['type'] = 'negative';
        break;
        # Positive
    # Positive
    case $response['code'] === 200:
        $response['type'] = 'positive';
        break;
}
# JSON
JSON::parse($response['code'], $response['type'], $response['message'], $response, true);
开发者ID:chrismademe,项目名称:php-starter,代码行数:23,代码来源:manage-post-new.php

示例4: switch

<?php

# Check user & validate data
switch (true) {
    # Not logged in
    case is_loggedin():
        JSON::parse(100, 'negative', '<i class="fa fa-exclamation-triangle"></i> You\'re already logged in!', null, true);
        break;
        # No post data
    # No post data
    case !is_form_data():
        JSON::parse(100, 'negative', '<i class="fa fa-exclamation-triangle"></i> There was a problem logging you in. (Error: No data received)', null, true);
        break;
}
# Create User Object
$_ce_user = new CMSEditor\User($_ce_config);
# New GUMP Object
$form = new GUMP();
# Get Input
$data = form_data();
# Validate Input
$form->validate($data, array('username' => 'required', 'password' => 'required'));
# Run GUMP
$response = $form->run($data);
# Get Response
if ($response === false) {
    JSON::parse(100, 'negative', $form->get_readable_errors(true));
} else {
    # Attempt login
    $_ce_user->login($data['username'], $data['password']);
}
开发者ID:chrismademe,项目名称:php-starter,代码行数:31,代码来源:ce-ajax-login.php

示例5: JSON

class object2
{
    var $firstattr = 'firstvalue';
    var $secondattr = 'secondvalue';
}
//---- variables ---------------------------------------------------------------
$JSON = new JSON();
$object1 = new object1();
$JSON2 = new Services_JSON();
$submitted = false;
//---- logic -------------------------------------------------------------------
$origjsonstring = $JSON->stringify($object1);
$newjsonstring = $JSON2->encode($object1);
$origjson = $_REQUEST["origjson"];
if (!empty($origjson)) {
    $origjsonprintr = $JSON->parse(stripslashes($origjson));
    $submitted = true;
} else {
    $origjsonprintr = "Not submitted";
}
$newjson = $_REQUEST["newjson"];
if (!empty($newjson)) {
    $newjsonprintr = $JSON2->decode(stripslashes($newjson));
} else {
    $newjsonprintr = "Not submitted";
}
//---- content -----------------------------------------------------------------
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<title>JSON parser test</title>
开发者ID:edmarmoretti,项目名称:i3geo,代码行数:31,代码来源:testsuite2.php

示例6: foreach

    # the file with the newly uploaded content.
    foreach ($data['data'] as $field) {
        # Set Filename
        $filename = ROOT_DIR . '/site/_content/index/' . $field['ID'] . '.html';
        # Check for file
        if (!is_writeable($filename)) {
            $unsaved++;
        }
        # Attempt to save content
        if (file_exists($filename) && file_put_contents($filename, trim($field['content'], "\t\r\n"))) {
            $saved++;
        }
    }
    # Check for success
    switch (true) {
        # All saved
        case $saved > 0 && $unsaved === 0:
            JSON::parse(200, 'positive', '<i class="fa fa-check-circle"></i> Changes saved.', null, true);
            break;
            # Some saved
        # Some saved
        case $saved > 0 && $unsaved > 0:
            JSON::parse(200, 'warning', '<i class="fa fa-check-circle"></i> Some changes were not saved.', null, true);
            break;
            # No saved
        # No saved
        case $saved === 0 && $unsaved > 0:
            JSON::parse(200, 'negative', '<i class="fa fa-check-circle"></i> Changes were not saved.', null, true);
            break;
    }
}
开发者ID:chrismademe,项目名称:php-starter,代码行数:31,代码来源:ce-update.php

示例7: testFormatError

 /**
  * @covers ::parse
  * @dataProvider formatErrors
  * @expectedException Firehed\Input\Exceptions\InputException
  * @expectedExceptionCode Firehed\Input\Exceptions\InputException::FORMAT_ERROR
  */
 public function testFormatError($json)
 {
     $parser = new JSON();
     $parser->parse($json);
 }
开发者ID:firehed,项目名称:input,代码行数:11,代码来源:JSONTest.php

示例8: array

# Check Method is Post
if (!is_form_data()) {
    JSON::parse(100, 'negative', 'Invalid request. Requests to ' . $path . ' must be POST', null, true);
}
# Actions
$actions = array(1, 0, -1);
# Sanitize form data
$data = Helpers::sanitizeInput(form_data());
# Check for post IDs
if (!isset($data['posts']) || !isset($data['action'])) {
    JSON::parse(100, 'negative', 'Missing data.', $data, true);
}
# Get Post IDs
$posts = json_decode($data['posts'], true);
# Typecast Action
$action = (int) $data['action'];
# Check Action is Valid
if (!in_array($action, $actions)) {
    JSON::parse(100, 'negative', 'Invalid action.', null, true);
}
# Create new Content Object
$content = new Content($_cck_types, $_cck_config);
# Update each post
foreach ($posts as $post) {
    if (!$content->update($post, array('status' => $action))) {
        JSON::parse(100, 'negative', 'Post ID: ' . $post . ' was not updated.', null, true);
    }
}
# Return result
JSON::parse(200, 'positive', 'Posts updated', form_data(), true);
开发者ID:chrismademe,项目名称:php-starter,代码行数:30,代码来源:cck-ajax-status.php

示例9: cck_url_alias

<?php

use CCK\Helpers;
# Check Method is Post
if (!is_form_data()) {
    JSON::parse(100, 'negative', 'Invalid request. Requests to ' . $path . ' must be POST', null, true);
}
# Sanitize form data
$data = Helpers::sanitizeInput(form_data());
# Check 'alias' is present
if (!isset($data['alias']) || !is_string($data['alias'])) {
    JSON::parse(100, 'negative', 'Alias input is not valid.', null, true);
}
# Generate Alias
$alias = cck_url_alias($data['alias']);
# Return result
JSON::parse(200, 'positive', 'Alias generate', array('alias' => $alias), true);
开发者ID:chrismademe,项目名称:php-starter,代码行数:17,代码来源:cck-ajax-alias.php

示例10: Media

<?php

use CCK\Media;
$media = new Media($_cck_config);
# Get All Media
if ($theMedia = $media->get($_GET)) {
    JSON::parse(200, 'success', 'Status: OK', $theMedia, true);
}
开发者ID:chrismademe,项目名称:php-starter,代码行数:8,代码来源:api-get-media.php


注:本文中的JSON::parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。