2

iOS アプリ/Web サービスを構築しています。iOS アプリは、次のようにデータを php scrip に送信します。

    NSError* error = nil;
    NSURLResponse  *res ponse = nil;

    NSArray * keys = [NSArray arrayWithObjects:@"addr", @"date", @"o_cond", nil];    
    NSArray * values = [NSArray arrayWithObjects:addr, date, o_cond, nil];

    NSDictionary * info = [NSDictionary dictionaryWithObjects:values forKeys:keys];
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:info options:NSJSONWritingPrettyPrinted error:&error];

    NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://myaddr.com/sendEmail.php"]];
    [req setHTTPMethod:@"POST"];
    [req setHTTPBody:jsonData];

    [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];

そしてphpはデータを受け取りました:

<?php
    // Get all the posted vars  
    $jsonInput = file_get_contents('php://input');
    $decoded = json_decode($jsonInput, true);

    $body = "Inspection Results for " . $decoded->{'addr'} . "\n\n";
    $body = $body . "Inspection date and time: " . $decoded->{'date'} . "\n\n";
    $body = $body . "Overall condition of asset: " . $decoded->{'o_cond'} . "\n\n"; ?>

しかし、何らかの理由で、php 側でデータを受け取ることができません。ここで何がうまくいかないのか誰にもわかりますか?

ありがとう

4

1 に答える 1

0

$decoded['addr']の代わりに試してください$decoded->{'addr'}。json_decode に連想配列を返すように指示していますが (2 番目の引数は true に設定されています)、代わりにオブジェクトにアクセスしようとしているようです。

于 2012-12-18T06:10:36.470 に答える